Thread Subject: Problem with Indexing!

Subject: Problem with Indexing!

From: Arch

Date: 5 Jun, 2008 10:13:06

Message: 1 of 6

I've a problem with finding the index in a single vector.
i've calculated some parameters for a document for some
values of theta ranging from -15 to +15 in steps of 5. that
means

1col -15
2col -10
3col -5
4col 0
5col 5
6col 10
7col 15

i find the maximum value out of these, but i dunno how to
get back the angle correspondingly using the positive matrix
indices. i.e., if the column number i get is 3rd, how do
calculate the actual -5?

Subject: Problem with Indexing!

From: Uwe Steinmann

Date: 5 Jun, 2008 10:39:02

Message: 2 of 6

Hi Arch,

maybe the function "find" will help you, but I don't
understand what you mean. Which variables do you have?
Could you please give an example?

Uwe

Arch <archforgroups@gmail.com> wrote in message <cb0a6834-
76ba-4437-8ff5-1e9937ad1e66@x1g2000prh.googlegroups.com>...
> I've a problem with finding the index in a single vector.
> i've calculated some parameters for a document for some
> values of theta ranging from -15 to +15 in steps of 5.
that
> means
>
> 1col -15
> 2col -10
> 3col -5
> 4col 0
> 5col 5
> 6col 10
> 7col 15
>
> i find the maximum value out of these, but i dunno how to
> get back the angle correspondingly using the positive
matrix
> indices. i.e., if the column number i get is 3rd, how do
> calculate the actual -5?

Subject: Problem with Indexing!

From: Archana Ananthanarayan

Date: 5 Jun, 2008 10:49:01

Message: 3 of 6

Thanks for responding.

Well, see i've some values in an array

Index Value
1 67
2 34
3 211
4 150
5 62
6 58
7 56

Now the indices are some counts. but the parameters are
calculated for some values of theta ranging from -15 to 15
in steps of 5. so 1 will correspond to calculation for theta
= -15. how do i retain the actual values - cos we can't
index arrays using negative indices!


"Uwe Steinmann" <uwe_steinmann@web.de> wrote in message
<g28fo6$fua$1@fred.mathworks.com>...
> Hi Arch,
>
> maybe the function "find" will help you, but I don't
> understand what you mean. Which variables do you have?
> Could you please give an example?
>
> Uwe
>
> Arch <archforgroups@gmail.com> wrote in message <cb0a6834-
> 76ba-4437-8ff5-1e9937ad1e66@x1g2000prh.googlegroups.com>...
> > I've a problem with finding the index in a single vector.
> > i've calculated some parameters for a document for some
> > values of theta ranging from -15 to +15 in steps of 5.
> that
> > means
> >
> > 1col -15
> > 2col -10
> > 3col -5
> > 4col 0
> > 5col 5
> > 6col 10
> > 7col 15
> >
> > i find the maximum value out of these, but i dunno how to
> > get back the angle correspondingly using the positive
> matrix
> > indices. i.e., if the column number i get is 3rd, how do
> > calculate the actual -5?
>

Subject: Problem with Indexing!

From: Yonathan Nativ

Date: 5 Jun, 2008 11:03:02

Message: 4 of 6

Hi Archana,

I'm not sure this is what you mean, but try this:

phi = -15:5:15;
vec = [67 34 211 150 62 58 56];
[M ind] = max(vec);
whatYouAreLookingFor = phi(ind);

Hoop it helped, and welcome to matlab :)

"Archana Ananthanarayan" <archana1985_ms@hotmail.com> wrote
in message <g28gat$qe8$1@fred.mathworks.com>...
> Thanks for responding.
>
> Well, see i've some values in an array
>
> Index Value
> 1 67
> 2 34
> 3 211
> 4 150
> 5 62
> 6 58
> 7 56
>
> Now the indices are some counts. but the parameters are
> calculated for some values of theta ranging from -15 to 15
> in steps of 5. so 1 will correspond to calculation for theta
> = -15. how do i retain the actual values - cos we can't
> index arrays using negative indices!
>
>
> "Uwe Steinmann" <uwe_steinmann@web.de> wrote in message
> <g28fo6$fua$1@fred.mathworks.com>...
> > Hi Arch,
> >
> > maybe the function "find" will help you, but I don't
> > understand what you mean. Which variables do you have?
> > Could you please give an example?
> >
> > Uwe
> >
> > Arch <archforgroups@gmail.com> wrote in message <cb0a6834-
> > 76ba-4437-8ff5-1e9937ad1e66@x1g2000prh.googlegroups.com>...
> > > I've a problem with finding the index in a single vector.
> > > i've calculated some parameters for a document for some
> > > values of theta ranging from -15 to +15 in steps of 5.
> > that
> > > means
> > >
> > > 1col -15
> > > 2col -10
> > > 3col -5
> > > 4col 0
> > > 5col 5
> > > 6col 10
> > > 7col 15
> > >
> > > i find the maximum value out of these, but i dunno how to
> > > get back the angle correspondingly using the positive
> > matrix
> > > indices. i.e., if the column number i get is 3rd, how do
> > > calculate the actual -5?
> >
>

Subject: Problem with Indexing!

From: Archana Ananthanarayan

Date: 5 Jun, 2008 11:09:02

Message: 5 of 6

Thanks a ton. It helped :)



"Yonathan Nativ" <yonathan_n_REMOVE-THIS@hotmail.com> wrote
in message <g28h56$lki$1@fred.mathworks.com>...
> Hi Archana,
>
> I'm not sure this is what you mean, but try this:
>
> phi = -15:5:15;
> vec = [67 34 211 150 62 58 56];
> [M ind] = max(vec);
> whatYouAreLookingFor = phi(ind);
>
> Hoop it helped, and welcome to matlab :)
>
> "Archana Ananthanarayan" <archana1985_ms@hotmail.com> wrote
> in message <g28gat$qe8$1@fred.mathworks.com>...
> > Thanks for responding.
> >
> > Well, see i've some values in an array
> >
> > Index Value
> > 1 67
> > 2 34
> > 3 211
> > 4 150
> > 5 62
> > 6 58
> > 7 56
> >
> > Now the indices are some counts. but the parameters are
> > calculated for some values of theta ranging from -15 to 15
> > in steps of 5. so 1 will correspond to calculation for theta
> > = -15. how do i retain the actual values - cos we can't
> > index arrays using negative indices!
> >
> >
> > "Uwe Steinmann" <uwe_steinmann@web.de> wrote in message
> > <g28fo6$fua$1@fred.mathworks.com>...
> > > Hi Arch,
> > >
> > > maybe the function "find" will help you, but I don't
> > > understand what you mean. Which variables do you have?
> > > Could you please give an example?
> > >
> > > Uwe
> > >
> > > Arch <archforgroups@gmail.com> wrote in message <cb0a6834-
> > >
76ba-4437-8ff5-1e9937ad1e66@x1g2000prh.googlegroups.com>...
> > > > I've a problem with finding the index in a single
vector.
> > > > i've calculated some parameters for a document for some
> > > > values of theta ranging from -15 to +15 in steps of 5.
> > > that
> > > > means
> > > >
> > > > 1col -15
> > > > 2col -10
> > > > 3col -5
> > > > 4col 0
> > > > 5col 5
> > > > 6col 10
> > > > 7col 15
> > > >
> > > > i find the maximum value out of these, but i dunno
how to
> > > > get back the angle correspondingly using the positive
> > > matrix
> > > > indices. i.e., if the column number i get is 3rd, how do
> > > > calculate the actual -5?
> > >
> >
>

Subject: Problem with Indexing!

From: Steven Lord

Date: 5 Jun, 2008 13:43:07

Message: 6 of 6


"Archana Ananthanarayan" <archana1985_ms@hotmail.com> wrote in message
news:g28gat$qe8$1@fred.mathworks.com...
> Thanks for responding.
>
> Well, see i've some values in an array
>
> Index Value
> 1 67
> 2 34
> 3 211
> 4 150
> 5 62
> 6 58
> 7 56
>
> Now the indices are some counts. but the parameters are
> calculated for some values of theta ranging from -15 to 15
> in steps of 5. so 1 will correspond to calculation for theta
> = -15. how do i retain the actual values - cos we can't
> index arrays using negative indices!

So you have:

index = (1:7).';
value = [67; 34; 211; 150; 62; 58; 56];
theta = (-15:5:15).';

To find the maximum value and its location in the value matrix, use:

[maxValue, maxValueLocation] = max(value);

You can then use maxValueLocation to locate the elements of index and theta
in the same position as the maxValue is in the value matrix:

maxIndex = index(maxValueLocation);
maxTheta = theta(maxValueLocation);

Note that if index and value were combined in one matrix:

indexAndValue = [index value];

you can still do this by indexing into the columns of indexAndValue in your
MAX call:

[maxValue, maxValueLocation] = max(indexAndValue(:, 2));
maxIndex = indexAndValue(maxValueLocation, 1);
maxTheta = theta(maxValueLocation);

--
Steve Lord
slord@mathworks.com


Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com