Hi,
I have a matrix like this
A=[1 0 0;
1 0 0;
0 2 0;
0 2 0;
0 0 3;
0 0 3;
1 0 0;
1 0 0;
0 2 0;
0 2 0;
0 0 3;
0 0 3]
I want the output to look like this A_Final = [1;1;2;2;3;3;1;1;2;2;3;3].
I used nonzeros, but the output is like this, [1,1,1,1,2,2,2,2,3,3,3,3], not what I wanted, help!
Thanks!

 Réponse acceptée

Adam
Adam le 15 Sep 2014
Modifié(e) : Adam le 15 Sep 2014

0 votes

A_Final = sum( A, 2 )

4 commentaires

I like this one, except it's missing a sort.
sort(sum(A,2));
Ruohui
Ruohui le 15 Sep 2014
Thanks!!!!!!
Adam
Adam le 15 Sep 2014
You don't want the sort. If you want them sorted then you'd just use nonzeros like Ruohui did originally.
Oh Sorry! I should have read his question more carefully!

Connectez-vous pour commenter.

Plus de réponses (1)

Guillaume
Guillaume le 15 Sep 2014
A possible way:
sortedA = sort(A, 2);
A_Final = A(:, 3);

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by