Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
count no of values and their coordinates

Subject: count no of values and their coordinates

From: LFG Tech

Date: 15 Mar, 2010 10:43:07

Message: 1 of 2

Hello Friends,

Suppose i have a mtrix

x = [1 2 3 4;
       5 6 7 8;
       9 8 5 9;
       7 7 7 7];

now I want to find the number of times the maximum value(in this case 9) appears.Also i wld like to get the coordinates of them (in this case 3,1 and 3,4).


thanks,
LFG

Subject: count no of values and their coordinates

From: Sadik

Date: 15 Mar, 2010 10:53:06

Message: 2 of 2

Hi,

maxValue = max(x(:));
[m,n] = find(x==maxValue);
numberOfMaxValues = length(m);

m will be [3;3] and n will be [1;4]. So if you want to see the coordinates side by side, you can do

coordinates = [m,n];

so that coordinates will be a 2-column matrix.

Best.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us