tags:

views:

54

answers:

3

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 the matlab and now I want to check for which column the output "1" is present. The name of the file is: out.data

Like in the first case- the "1" is present in the column 3rd. How do I write it in matlab?

A: 

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

>> b = a';
>> rem(find(b(:) == 1),3) + 1
ysap
+2  A: 
output = [0 0 1 ; 1 0 0 ; 0 1 0];

[~,index] = max(output, [], 2)
index =
     3
     1
     2
merv
+1  A: 

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).

Matt Mizumi

related questions