how to formulate logical matrix in a loop?

조회 수: 1 (최근 30일)
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar 2018년 10월 24일
댓글: Andrei Bobrov 2018년 10월 25일
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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2018년 10월 25일
A = 1:10;
idx = A(:) == A(:)'
  댓글 수: 2
Shubham Mohan Tatpalliwar
Shubham Mohan Tatpalliwar 2018년 10월 25일
what should i change to have a 5 rows with a step of 2
Andrei Bobrov
Andrei Bobrov 2018년 10월 25일
what should i change to have a 5 rows with a step of 2
?
A = 1:2:10;
idx = A(:) == A(:)';

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 10월 24일
편집: madhan ravi 2018년 10월 24일
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
madhan ravi
madhan ravi 2018년 10월 25일
what do you mean by the above code?
madhan ravi
madhan ravi 2018년 10월 25일
What should be the result after the loop?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by