开发者

How can I find specific elements in a matrix in MATLAB?

I have a data set file that has 3 columns in it.

0 0 1
1 0 0
0 1 0

I have the loaded the data file into MATLAB and now I want to check for which column the output "1" is present.

The name of the file is: 开发者_C百科out.data

In the first row "1" is present in the 3rd column. How do I write it in matlab?


output = [0 0 1 ; 1 0 0 ; 0 1 0];

[~,index] = max(output, [], 2)
index =
     3
     1
     2


you can also do

[junk,column_index] = max(data,[],2);

then column_index corresponds the first column in each row that has the 1 (assuming the data is well behaved).


This is without actually checking it (don't have matlab available right now), but might work:

>> b = a';
>> rem(find(b(:) == 1),3) + 1
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜