How to delete columns of a matrix containing specific values in bottom row
11 views (last 30 days)
Show older comments
Hi. I am working on a program that generates a 2xN matrix that looks something like this
ModRows = [7 11 21 27 243 2817 3114 3489;...
2 2 4 6 13 279 1 150]
What I want to do is search the matrix for values in the second row that are below 2 and delete the respective column, so I would get something like this, for example:
ModRows = [21 27 243 2817 3489;...
4 6 13 279 150;]
I have no idea where to start. I can't use an index i from 1 to the size of ModRows, because whenever I delete a column, ModRows becomes shorter, resulting in an error.
Any help would be much appreciated!
Marc
0 Comments
Accepted Answer
per isakson
on 21 Sep 2013
Edited: per isakson
on 21 Sep 2013
Test this:
is_exclude = ModRows(end,:) < 2;
ModRows( :, is_exclude ) = [];
or did you mean "<= 2"?
And search for "Using Logicals inArray Indexing" in the help
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!