How to find certain elements in a matrix in MATLAB?

I have a dataset file that has three columns.

0 0 1
1 0 0
0 1 0

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

File name: out.data p>

In the first row, “1” is present in the third column. How to write it to matlab?

+3
source share
3 answers
output = [0 0 1 ; 1 0 0 ; 0 1 0];

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

you can also do

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

this column_indexcorresponds to the first column in each row, which has 1 (provided that the data behaves well).

+1
source

( MATLAB), :

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

Source: https://habr.com/ru/post/1759027/


All Articles