Arrays: What does [] do inside an array and is their any other command that serves the same purpose?
3 views (last 30 days)
Show older comments
I would like to know what the purpose of the ''[]'' is in the example below i.e. What does [] do in something like this:
[Distance,ClosestNumbers] = min(Distance,[],3)
Is their any other way to write out the above without using the [] and using something else that serves the same purpose, say if i didnt want to use[].
4 Comments
Image Analyst
on 5 Sep 2018
It doesn't seem to do that either. Plus, you didn't change it back to the original question.
Answers (2)
Image Analyst
on 3 Sep 2018
Your Distance must be a 3-dimensional array, like an RGB image is. You can go through each plane one at a time.
rgbImage = imread('peppers.png');
imshow(rgbImage);
title('original image');
% Initialize min image to be first plane.
minImage = rgbImage(:, :, 1);
for plane = 2 : size(rgbImage, 3)
minImage = min(minImage, rgbImage(:, :, plane));
end
figure;
imshow(minImage, []);
title('minImage');
though I really don't know why you'd want to do that instead of simply using min() with the [] and dimension direction option.
0 Comments
Stephen23
on 3 Sep 2018
Edited: Stephen23
on 3 Sep 2018
"What does [] do when played inside something like this:"
min(Distance,[],3)
In this case [] simply acts as a placeholder for an "unused" input, which is required for some syntaxes of min, max, and several other functions. You can find out which syntaxes by reading the min documentation. You can also read my detailed explanation here:
"Say if i didnt want to use ''[]'' what else can i use that will serve the same purpose"
There is nothing else that will serve that purpose: the documentation clearly shows to use [] for those specific syntaxes. The documentation does not say that anything else will work.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!