Reputation: 1509
I have an m x n Matrix, which I call data.
The last column consist of values between 1 and 7.
I want to find the value 7 in that column , and change the values of the other column which are in the same row as the value 7.
How can i do this?
Upvotes: 1
Views: 346
Reputation: 3116
Alternative version of Oli Charlesworth's answer without find
:
n=6;
% Build random matrix
data=[rand(7,n) (1:7)'];
% Replace row with last column at 7 with vector (1:7)
data(data(:,end)==7,:)=(1:7);
Upvotes: 0
Reputation: 272467
idx_row = find(data(:,end) == 7);
data(idx_row,:) == data(idx_row,end);
Upvotes: 1