Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore output variables in matlab?

Tags:

matlab

[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?

like image 739
Mohammad Moghimi Avatar asked Dec 15 '22 18:12

Mohammad Moghimi


1 Answers

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.

like image 137
Andreas H. Avatar answered Dec 29 '22 10:12

Andreas H.