how to formulate logical matrix in a loop?
Ältere Kommentare anzeigen
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
Weitere Antworten (1)
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
am 24 Okt. 2018
No need to use logical indexing , see the above illustration
Shubham Mohan Tatpalliwar
am 24 Okt. 2018
madhan ravi
am 24 Okt. 2018
See the edited answer ,problem solved!
Shubham Mohan Tatpalliwar
am 24 Okt. 2018
Bearbeitet: Shubham Mohan Tatpalliwar
am 25 Okt. 2018
madhan ravi
am 24 Okt. 2018
Bearbeitet: madhan ravi
am 24 Okt. 2018
hows this related to the question??? what did you do in the above comment?
Shubham Mohan Tatpalliwar
am 25 Okt. 2018
Bearbeitet: Shubham Mohan Tatpalliwar
am 25 Okt. 2018
madhan ravi
am 25 Okt. 2018
I know but you don’t have Use a loop
madhan ravi
am 25 Okt. 2018
A=[1,2,3,4,5,6,7,8,9,10]
idy=zeros(1,length(A));
for i=1:1:10
idx22=find(A >=(i) & A<(i+1));
idy(i,idx22)=1;
end
madhan ravi
am 25 Okt. 2018
what do you mean by the above code?
madhan ravi
am 25 Okt. 2018
What should be the result after the loop?
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!