フィルターのクリア

how find last row<>0

2 ビュー (過去 30 日間)
piero
piero 2023 年 8 月 12 日
コメント済み: piero 2023 年 8 月 12 日
a=[3 4 5 0 3 4 0;4 5 0 0 0 0 0;0 0 0 0 0 0 0]
a =
3 4 5 0 3 4 0
4 5 0 0 0 0 0
0 0 0 0 0 0 0
i want to know the last rows wich element are ==0 ..solution idx=2!
i try this solution :find(sum(a,2)==0)-1 but it's no good because example :the sum 3 3 0 -3 -3 0 =0 but is not correct
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 8 月 12 日
Your phrasing is not clear (atleast to me).
a=[3 4 5 0 3 4 0;4 5 0 0 0 0 0;0 0 0 0 0 0 0]
a = 3×7
3 4 5 0 3 4 0 4 5 0 0 0 0 0 0 0 0 0 0 0 0
As you said, the output for the above array is 2, what is the logic behind that?
piero
piero 2023 年 8 月 12 日
a=flip(a)
for i=1:height(a)
if sum(a(i,:),2)>0 and sum(a(i+1,:),2)==0
memRow=i;
break;
end
end
t's similar this code but i don't to use loop and sum
I want to store the idx of the last row where there is at least one number <>0

サインインしてコメントする。

採用された回答

Matt J
Matt J 2023 年 8 月 12 日
idx = find(~any(a,2),1,'last')-1

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by