How to get arg min of an N-dimensional Matrix ?

Hi, i'm having an image of size[280,307,191] and i want to get the argmin of it,Any help?

 Accepted Answer

James Tursa
James Tursa on 15 Apr 2013
Edited: James Tursa on 15 Apr 2013
[m n] = min(M(:));
[x y z] = ind2sub(size(M),n);
x, y, z will be the indexes (i.e., argmin) of the minimum value of your 3D array M.

2 Comments

thanks but what are the m & n ?
The documentation of min explains this exhaustively already. Type this in Matlab's command window:
help min
doc min
and read it.

Sign in to comment.

More Answers (3)

How do you define argmin? If it is the global min, you can get it as follows:
min(M(:))
where M is your 3D array.

4 Comments

i don't know what argmin means actually,
i have an equation like this :
x = arg min |g-u|.^2 g and u are 2 multibanded images
and im trying to implement it in matlab
Why do you want to implement something, when you do not know its mathematical meaning?
can you please explain what values should I give for M ??
Hi Sreeda M A! Example:
M = randi(400,280,307,191);

Sign in to comment.

Or:
min(min(min(M)))

2 Comments

Nope, this will return the minimum value and not the index of the minimum value
Just use [~,linIdx] = min(M(:)) and then convert to subscripts using IND2SUB.

Sign in to comment.

If you're using release R2019a or later, you probably want to call min with the 'all' dimension input and the 'linear' flag.

Community Treasure Hunt

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

Start Hunting!