## How can i find the column number in an array?

### Priyanka Bhasker (view profile)

on 20 Jan 2019
Latest activity Commented on by per isakson

### per isakson (view profile)

on 21 Jan 2019
I have imported data from a .txt file into matlab. The question is to find the column number of the column with the highest average. How do I find the column number that corresponds to the highest average value?

### per isakson (view profile)

Answer by per isakson

### per isakson (view profile)

on 20 Jan 2019
Edited by per isakson

### per isakson (view profile)

on 20 Jan 2019

Try this
M = rand( 6 ); % Sample data
[~,ixc] = max(mean( M, 1 ));

per isakson

### per isakson (view profile)

on 21 Jan 2019
Programming is complicated:(
"How do I find the column number that corresponds to the highest average value?" So I added: Given that there is such a number.
Image Analyst

### Image Analyst (view profile)

on 21 Jan 2019
Well as long as the matrix is not all null or all nan, there will be a max, and it will occur at one or more columns. Super robust code would check for the "all null" or "all nan" situation.
per isakson

### per isakson (view profile)

on 21 Jan 2019
Thank you for your comments. I just learned that both mean and max have nanflag the deault values of which are different.
"all null", but there is no null in Matlab?