for loops and if statements
조회 수: 11 (최근 30일)
이전 댓글 표시
I am try to index all the 5's in this array, need some help.
R12 = randi(12,12);
reshape (R12,[],1);
Ze = reshape 9R12,[],1);
NodataPt = length(Ze);
Seindex = zeros(NoDataPt,1)
for i = 1:1:NoDataPt
value = Ze(i);
if value ==5;
count = count + 1;
SeIndex(count,1) = 1;
end
end
댓글 수: 0
답변 (2개)
David Hill
2021년 3월 15일
Not sure what all the reshaping is about, but to find the indexes of elements in a==5:
a=randi(12,12);
idx=find(a==5);
댓글 수: 0
Walter Roberson
2021년 3월 15일
R12 = randi(12,12);
Ze = reshape(R12,[],1);
NodataPt = length(Ze);
Seindex = zeros(NoDataPt,1)
for i = 1:1:NoDataPt
value = Ze(i);
if value ==5;
count = count + 1;
SeIndex(count,1) = 1;
end
end
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!