필터 지우기
필터 지우기

How to work with loops?

조회 수: 2 (최근 30일)
ahmad Mohammadi
ahmad Mohammadi 2022년 10월 18일
댓글: ahmad Mohammadi 2022년 10월 18일
Hi,
I wrote down this code, however, it gives me the error " Arrays have incompatible sizes for this operation. Error in Code (line 5) row = find(X==i);"
X = [12 12 12 1 1 1 1 1]
for i= unique(X)
row = find(X==i)
for j=[row]
i have some codings here
end
end
Can you please help me? Thanks,
  댓글 수: 2
David Hill
David Hill 2022년 10월 18일
Runs fine.
X = [12 12 12 1 1 1 1 1];
a=[];
for i= unique(X)
row = find(X==i);
for j=row
a=[a,5];
end
end
a
a = 1×8
5 5 5 5 5 5 5 5
ahmad Mohammadi
ahmad Mohammadi 2022년 10월 18일
Thank you very much. Yes, the problem was X which was:
X = [12; 12; 12; 1; 1; 1; 1; 1];
I did not notice that.

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

답변 (0개)

카테고리

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