Change in Matrix (m x n) in matlab
I have an m x n Matrix, which I call d开发者_高级运维ata.
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?
idx_row = find(data(:,end) == 7);
data(idx_row,:) == data(idx_row,end);
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);
精彩评论