apply the min index to an array of the same size

2 visualizaciones (últimos 30 días)
hamed amini
hamed amini el 16 de Abr. de 2017
Comentada: hamed amini el 16 de Abr. de 2017
A and B are arrays with the same size. e.g.
>> size(A) = [2,4,3,5]; % A is a 4 dimensional matrix
>> size(B) = [2,4,3,5]; % B has the same size as A
>> [minA, minAind] = min(A,[ ],4);
size(minA) = [2,4,3]; %min will reduce one of the dimensions
How to extract the elements in B with the same index as minAind?

Respuesta aceptada

hamed amini
hamed amini el 16 de Abr. de 2017
I found the answer; here is an example when the min is applied along the 3rd dimension:
>> a=rand(2,3,4,5);
>> [amin, aind] = min(a,[],3);
>> [a1,a2,a4]= ndgrid([1:size(a,1)],[1:size(a,2)],[1:size(a,4)]);
>> allind = sub2ind(size(a), a1, a2,squeeze(aind), a4);
>> a(allind)-amin % ==> this would be all zeros, i.e. allind is the right index.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by