for loops and if statements

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

回答 (2 件)

David Hill
David Hill 2021 年 3 月 15 日

0 投票

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);
Walter Roberson
Walter Roberson 2021 年 3 月 15 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

質問済み:

2021 年 3 月 14 日

回答済み:

2021 年 3 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by