4
[dummy index] = sort(A);

I want to ignore the first output of sort function and just keep the indices. When I use the above I get a warning in the matlab editor that:

The value assigned to dummy is appears to be unused.

and it suggest to use ~ instead. When I use ~.

[~ index] = sort(A);

I got the following error:

use ~ to ignore a value is not permitted in this context.

Anyone has a solution for this?

1
  • I'm confused. There is no use of ~ in your example that you say fails. Commented Oct 12, 2012 at 2:07

2 Answers 2

13

You have to add a comma and separate the output arguments to get ~ to work.

The following works

[dummy index] = sort(A);
[dummy, index] = sort(A);
[~, index] = sort(A);

but

[~ index] = sort(A);

fails.

Sign up to request clarification or add additional context in comments.

Comments

0

It does work, though your question does not even show you using a ~ where you say you get an error.

A = rand(1,5);
[~,ind] = sort(A);

ind
ind =
     3     5     1     2     4

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.