# finding index of min value in a matrix

6 visualizzazioni (ultimi 30 giorni)
bkshn il 2 Dic 2014
Risposto: Degar DC il 14 Giu 2022
Hello
I have a matrix and I want to compare three element of this matrix and find min between them and then I want to know the column number of min element.
Could you help me ?
thanks
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Azzi Abdelmalek il 2 Dic 2014
post an example

Accedi per commentare.

### Risposta accettata

Mohammad Abouali il 2 Dic 2014
Modificato: Mohammad Abouali il 2 Dic 2014
So, you know what elements of the matrix you want to check?
If that is so, then let's say the row and column of those three elements are defined as:
rowIdx=[r1,r2,r3];
colIdx=[c1,c2,c3];
mat3Elements=myMatrix(sub2ind(size(myMatrix),rowIdx,colIdx);
[minValue,minIdx]=min(mat3Elements);
disp(['Min values is: ' num2str(minValue)])
disp('column: ')
disp(colIdx(minIdx))
if you want the min value of the entire matrix that is easier
[minValue,minIdx]=min(myMatrix(:));
disp(['Min values is: ' num2str(minValue)])
disp('column: ')
[~,col]=ind2sub(size(myMatrix),minIdx);
disp(col)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Degar DC il 14 Giu 2022
a is the result matrix
[ min_value , min_index ]=min(a)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Matrix Indexing 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