Matrix
A=
9
3
4
5
6
7
find the min value in the matrix, and take that position
and swap this matrix
Z=
5
3
8
1
4
7
swap that min value Position in a A matrix and the first value in Z matrix

 Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 17 Oct 2013
Modifié(e) : Andrei Bobrov le 17 Oct 2013

1 vote

[v,ia] = min(A);
A(ia) = Z(1);
Z(1) = v;
ADD
[~,ia] = min(A);
Z([ia,1]) = Z([1,ia]);

3 commentaires

Anusha
Anusha le 17 Oct 2013
Z's first position 5 and the min(A) i.e) second position 3 should be swapping.. not replaced
Andrei Bobrov
Andrei Bobrov le 17 Oct 2013
corrected, see ADD part in answer.
Anusha
Anusha le 17 Oct 2013
yes thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by