how find last row<>0

2 Ansichten (letzte 30 Tage)
piero
piero am 12 Aug. 2023
Kommentiert: piero am 12 Aug. 2023
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 Kommentare
Dyuman Joshi
Dyuman Joshi am 12 Aug. 2023
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 am 12 Aug. 2023
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 12 Aug. 2023
idx = find(~any(a,2),1,'last')-1

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by