find the index who have the max value in cell structure
3 ビュー (過去 30 日間)
古いコメントを表示
i have a cell structure like this:
ex1=[1 2 3];
ex2=[2 3 0];
for i=1:3
a(i).b=struct('ex1',ex1(i),'ex2',ex2(i));
end
how can i find the index of a(i) who have the max value of ex1 but the ex2 must be greater than 0?
0 件のコメント
採用された回答
Voss
2022 年 8 月 23 日
編集済み: Voss
2022 年 8 月 30 日
ex1=[1 2 3];
ex2=[0 3 2];
for i=1:3
a(i).b = struct('ex1',ex1(i),'ex2',ex2(i));
end
temp = [a.b];
posidx = find([temp.ex2] > 0);
[maxval,tempidx] = max([temp(posidx).ex1]);
maxidx = posidx(tempidx);
disp(maxval);
disp(maxidx);
2 件のコメント
Voss
2022 年 8 月 30 日
You're right. I've changed the answer and changed the ex2 to [0 3 2], and it now gives the expected result.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!