Threshold for each column of a mxn matrix

1 回表示 (過去 30 日間)
smo
smo 2015 年 9 月 4 日
コメント済み: smo 2015 年 9 月 4 日
Hi, if say I have a m x n matrix and I want to set a certain threshold for column 1 and certain threshold for column 2, how can I do this please?
For example, if I have
[1 11
2 12
3 13
4 14
5 15]
and I want to set column1>2 AND at the same time column2<15, which means at the end will left
[3 13
4 14]
how can i code this please? this is just an example as my data file is actually much bigger. Thank you very much.

採用された回答

Image Analyst
Image Analyst 2015 年 9 月 4 日
Try this:
m = [1 11
2 12
3 13
4 14
5 15]
rowsToKeep = m(:,1) > 2 & m(:, 2) < 15
out = m(rowsToKeep, :)
  6 件のコメント
Image Analyst
Image Analyst 2015 年 9 月 4 日
I just tried it and it worked fine:
m = [1 11
2 12
3 13
4 14
5 15]
rowsToKeep = m(:,1) > 2 & m(:,1) < 5 & m(:, 2) < 15
out = m(rowsToKeep, :)
and I see
m =
1 11
2 12
3 13
4 14
5 15
rowsToKeep =
0
0
1
1
0
out =
3 13
4 14
So, what did you do differently? Your script is not called m.m is it?
smo
smo 2015 年 9 月 4 日
Sorry about that! I made a very stupid mistake. and it is working now. thank you very much! have a nice weekend.

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by