Arrays: What does [] do inside an array and is their any other command that serves the same purpose?

3 Ansichten (letzte 30 Tage)
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 Kommentare
Image Analyst
Image Analyst am 5 Sep. 2018
It doesn't seem to do that either. Plus, you didn't change it back to the original question.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 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.

Stephen23
Stephen23 am 3 Sep. 2018
Bearbeitet: Stephen23 am 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.

Kategorien

Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by