Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / MATLAB / July 2008



Tip: Looking for answers? Try searching our database.

finding position in an array??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MURTADHA - 21 Jul 2008 00:45 GMT
Hi

please can anyone help me with this issue

I have array like c
c=[1 2 5 1 9 6 0 4]
by using max (max(c)) function we can find the largest
number in this array (9), but how to find its position,
which must be c(1,5)??

thank you
Teg Veece - 21 Jul 2008 01:03 GMT
Okay, well I suppose a fairly intuitive way of doing it would be to find the max first.

MAX = max(c)

Then you want to find where this max occurs within c.

You can do this using the "find" command. Check the help section of matlab for more details.

LOCATION = find(c == MAX) will return a single number indicating how far into the matrix the max occurs.
In this case, LOCATION would be 5 (the fifth element of c).

But find can all return more than 1 value.

[ROW,COL] = find(c == MAX)

COL will be what column the max occurs in and ROW will be what row it occurs in.
So here ROW= 1 and COL= 5.
MURTADHA - 21 Jul 2008 13:54 GMT
Thank you for your replay

But is it the same if I want to search a certin row in an
array??

Must it be like this
MAX=max(c(i,:))

and what to put instead of the --- bellow

find(--- == MAX)
Loren Shure - 21 Jul 2008 18:12 GMT
> Thank you for your replay
>
[quoted text clipped - 7 lines]
>
> find(--- == MAX)

Read the help for max, and pay attention to the 3rd possible input and
the 2nd output.

Signature

Loren
http://blogs.mathworks.com/loren/

MURTADHA - 22 Jul 2008 10:06 GMT
"MURTADHA " <m.aldirawy@yahoo.com> wrote in message
<g620ta$bss$1@fred.mathworks.com>...
> Thank you for your replay
>
[quoted text clipped - 7 lines]
>
> find(--- == MAX)

Hi guys

I found the solution
It must be like this
find(c(i,:)==MAX)

Regards
Murtadha
us - 21 Jul 2008 01:05 GMT
"MURTADHA ":
<SNIP does not read his/her help...

> by using max (max(c)) function we can find the largest
> number in this array (9), but how to find its position,
> which must be c(1,5...

a hint:

    help max;

% now, peruses(!) the output carefully(!)...
% in particular, $2

us
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.