how to formulate logical matrix in a loop?

2 Ansichten (letzte 30 Tage)
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar am 24 Okt. 2018
Kommentiert: Andrei Bobrov am 25 Okt. 2018
i am having a matrix and want to separate them in the depending on its value
A=[1,2,3,4,5,6,7,8,9,10]
expected result are
idx1=[1,0,0,0,0,0,0,0,0,0] % for 1
...
idx10=[0,0,0,0,0,0,0,0,0,1] % for 10

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 25 Okt. 2018
A = 1:10;
idx = A(:) == A(:)'
  2 Kommentare
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar am 25 Okt. 2018
what should i change to have a 5 rows with a step of 2
Andrei Bobrov
Andrei Bobrov am 25 Okt. 2018
what should i change to have a 5 rows with a step of 2
?
A = 1:2:10;
idx = A(:) == A(:)';

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

madhan ravi
madhan ravi am 24 Okt. 2018
Bearbeitet: madhan ravi am 24 Okt. 2018
A=[1,2,3,4,5,6,7,8,9,10]
RESULT = zeros(1,numel(A));
RESULT1= RESULT;
for i = 1:numel(A)
idx(i)=A(i)==1;
idx1(i)=A(i)==10;
end
RESULT(idx) = A(idx)
RESULT1(idx1) = A(idx1)
  10 Kommentare
madhan ravi
madhan ravi am 25 Okt. 2018
what do you mean by the above code?
madhan ravi
madhan ravi am 25 Okt. 2018
What should be the result after the loop?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by