フィルターのクリア

select a portion of the matrix

2 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 8 月 5 日
回答済み: Star Strider 2023 年 8 月 5 日
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?

採用された回答

Star Strider
Star Strider 2023 年 8 月 5 日
One approach —
LD = load('matrix_C.mat');
C = LD.C
C = 7×5
81 43 134 120 297 82 32 77 73 182 83 0 50 45 116 84 0 0 35 76 85 0 0 0 60 86 0 0 0 44 87 0 0 0 41
idx = find(sum(C(:,[2 3 4])==0,2)==3, 1);
Result = C(1:idx,:)
Result = 5×5
81 43 134 120 297 82 32 77 73 182 83 0 50 45 116 84 0 0 35 76 85 0 0 0 60
.

その他の回答 (1 件)

the cyclist
the cyclist 2023 年 8 月 5 日
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
C = 7×5
81 43 134 120 297 82 32 77 73 182 83 0 50 45 116 84 0 0 35 76 85 0 0 0 60 86 0 0 0 44 87 0 0 0 41
indexToLastRow = find(all(C(:,2:4)==0 & C(:,5)~=0,2),1);
C(1:indexToLastRow,:)
ans = 5×5
81 43 134 120 297 82 32 77 73 182 83 0 50 45 116 84 0 0 35 76 85 0 0 0 60

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by