Finding Max Value From Matlab Variable

Hi Experts,
I have a variable
out
i want to extract the max value and its corresponding cell value i.e 17531 and 3 .....i used max function i.e
a = max(out);
but it is displaying 4 17531.............I dont know why it is showing 4 instead of 3???Please help

 Respuesta aceptada

Andreas Goser
Andreas Goser el 22 de Mzo. de 2015
Editada: Andreas Goser el 22 de Mzo. de 2015
That is a nice one! But in the doc it says
"If A is a matrix, then max(A) treats the columns of A as vectors and returns a row vector of largest elements."
So you maybe want to do something else? Like
[a,ix]=max(out(:,2))

3 comentarios

rizwan
rizwan el 22 de Mzo. de 2015
Editada: rizwan el 22 de Mzo. de 2015
Thanks it worked for me.....
Can you please guide in this scenario..
out = [a,histc(idx(:),a)]; % out variable having cluster number and cluster size
[a,ix]= max(out(:,2)); %getting the max value in a and its index in ix variable
[row , col] = find(idx ==ix);%using find func in checking where in idx the ix exists and storing the row col index in row and col
mx_row = max(row); %getting max row index
mx_col = max(col);%getting max col index
for i = 1 : mx_row %for loop till max row index
for j = 1 : mx_col %for loop till max col index
cp = I(row(i),col(j));% getting the row and col indexes and accessing the element from I and store it in cp
end
end
There is error for loops it is not storing the values at corresponding locations.. Can you please guide where i m having error on the above following code???
Andreas Goser
Andreas Goser el 22 de Mzo. de 2015
If you can provide data and code together, that is easier for me to help. Otherwise I need to make guesses.
Image Analyst
Image Analyst el 22 de Mzo. de 2015
This latest question is a duplicate of a different one. One that I responded to in http://www.mathworks.com/matlabcentral/answers/184466-for-loop-issue-in-code#comment_273784

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Mzo. de 2015

Comentada:

el 22 de Mzo. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by