select a portion of the matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alberto Acri
am 5 Aug. 2023
Beantwortet: Star Strider
am 5 Aug. 2023
Hi! I have the matrix 'matrix_C'. How can I stop (in this case) at the fifth row, i.e. when column 2,3,4 have 0 and column 5 a number?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1450982/image.png)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 5 Aug. 2023
One approach —
LD = load('matrix_C.mat');
C = LD.C
idx = find(sum(C(:,[2 3 4])==0,2)==3, 1);
Result = C(1:idx,:)
.
0 Kommentare
Weitere Antworten (1)
the cyclist
am 5 Aug. 2023
The following does what you asked for, for this matrix. The "rule" you specified was not perfectly clear to me, though, so this may not generalize to other matrices in the way you want.
load("matrix_C.mat","C")
C
indexToLastRow = find(all(C(:,2:4)==0 & C(:,5)~=0,2),1);
C(1:indexToLastRow,:)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!