Mike Miller
Mike Miller

Reputation: 263

Median of the row of an array Matlab

I'm looking to find the median of just a specific row of an m x n array. I couldn't find anything useful in the Matlab help section. E.g. if I had a small array

  [1 2 4; 2 3 4; 6 2 8] 

how would I find the median of row 2? Many thanks.

Upvotes: 0

Views: 459

Answers (2)

Jason S
Jason S

Reputation: 189686

Search for median in google or matlab (doc median) and you will find the median function.

If you want to find the median of row 2, just use row,column indexing syntax, where : means all entries:

A = [1 2 4; 2 3 4; 6 2 8]; 
median(A(2,:))

Upvotes: 4

Nick
Nick

Reputation: 3193

You could try to use:

A = [1 2 4; 2 3 4; 6 2 8];

medianRows = median(A, 2); % to find every rows' median

medianRows(2)

Or:

medianRow2 = median(A(2, :)); % every column of 2nd row

Upvotes: 1

Related Questions