Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this MATLAB statement for: [M N ~] = size(imge);?

Tags:

matlab

What does this statement mean???

[M N ~] = size(imge);

I don't understand the reason to use this "~", and this statement also gives an error message.

like image 476
chee Avatar asked Jul 20 '11 18:07

chee


1 Answers

In MATLAB versions since 2009b, you can use the tilde (~) to ignore outputs which you don't need. If it gives you an error, that means your version doesn't support this use of the tilde and you have to replace it with a dummy variable name as so:

[M N dummy] = size(imge);

As Sumona explains, M will contain the number or rows in the image and N the number of columns; dummy will be 1 (for one black-and-white image), 3 (for one colour image) or an arbitrary integer (for an image stack).

Usually it only makes sense to use the tilde if there are other parameters you are interested afterwards. size is an exception here in that it checks (using nargout) how many outputs it should produce and changes its behavior accordingly, as documented here..

That is,

test = zeros(3,4,5);
[M N dummy] = size(test);

produces M=3,N=4 as one would expect, but

test = zeros(3,4,5);
[M N] = size(test);

produces M=3,N=20.

In your particular case, I assume imge is an image stack and the programmer wanted to find out the size of the individual images, but not how many there are.

like image 116
Jonas Heidelberg Avatar answered Sep 25 '22 16:09

Jonas Heidelberg