Reputation: 87
I have something like the following:
a =
5 1 4
2 1 1
5 2 8
I am looking to return the minimum value of the third row
b = min(a(3,:));
b =
2
How would I be able to return the entire column (i.e. (1;1;2)) and then subtract remove that column from the matrix?
Any suggestions?
Upvotes: 2
Views: 287
Reputation: 15345
If you want to subtract the column with the minimum value from the whole matrix (as was initially asked) use bsxfun like so:
[v, i] = min(a(3,:));
a = bsxfun(@minus, a, a(:, i));
UPDATE:
You can extract and eliminate the column from a
like so:
[v, i] = min(a(3,:));
col = a(:, i);
a(:, i) = [];
Upvotes: 5
Reputation: 20915
In order to remove the column, use
a(:,i) = [];
where i
is the index of the column
Upvotes: 3