开发者

Change in Matrix (m x n) in matlab

开发者 https://www.devze.com 2023-04-04 21:10 出处:网络
I have an m x n Matrix, which I call d开发者_高级运维ata. The last column consist of values between 1 and 7.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消