creating a new matrix without certain rows with elements below a certain value

I want to create a new matrix which is has the same values as my original matrix, M, minus those rows whose first column values are less than 3.
Does anyone know how I could correct my code to do this?
M=set7;
Mm=table2array(M);
N=Mm(Mm(:,1)>=3)
for (Mm(1:end,1)>=3)
B=Mm(:,2)
end
Nn=zeros(size(B,2))
Nn=(N,B);
Thanks!

 採用された回答

Tommy
Tommy 2020 年 6 月 8 日
If I'm understanding correctly, I believe your third line is enough (with the addition of a colon in the second subscript of M to avoid linear indexing):
idx = M(:,1) >= 3; % indices of rows to keep
N = M(idx,:);

2 件のコメント

Em
Em 2020 年 6 月 8 日
Thanks, its working perfectly!
Tommy
Tommy 2020 年 6 月 8 日
Happy to help!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2017b

質問済み:

Em
2020 年 6 月 7 日

コメント済み:

2020 年 6 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by