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

3 visualizzazioni (ultimi 30 giorni)
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 Commenti

Accedi per commentare.

Risposte (2)

Image Analyst
Image Analyst il 3 Set 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 il 3 Set 2018
Modificato: Stephen23 il 3 Set 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.

Categorie

Scopri di più su MATLAB Coder in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by