Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: sorting, ranking
Replies: 10   Last Post: Jan 14, 2013 1:25 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 17,945
Registered: 12/7/04
Re: sorting, ranking
Posted: Aug 21, 2009 3:53 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Wyatt " <hello@hello.com> wrote in message
> that did the trick steve. It just seems to me that
> rank = temp(I)
> should be valid syntax,

It is. It just doesn't do what you expect it to do.

> and is more intuitive than writing
> rank(I) = temp

Why do you say that? "rank = temp(I)" is a valid MATLAB command in this
scenario, but so is "rank = I.^2" or "rank = sin(cos(tan(I)))". Each of
those commands do something different; for the application you described in
your original post, the command that does what you want is "rank(I) = temp".

Although you probably shouldn't use rank as a variable name, unless you're
okay with not being able to use the RANK function in the same piece of code.

> perhaps because I'm thinking that if I wanted to arbitrarily pull out
> values [7 4 9 1] from a vector A I would write
> A([7 4 9 1])
> and it would give me the 7th 4th 9th and 1st values from A in that order.

Yes. And if you wanted to store 1:4 into the 7th, 4th, 9th, and 1st
elements of A, you'd use:

A([7 4 9 1]) = (1:4);

Just because one command works does not necessarily rule out a modification
of that command also working and doing something slightly different.

Steve Lord

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.