problems with matrix splitting
Ältere Kommentare anzeigen
Hello everyone, I want to split the matrix in such a way that when elements of 1st column are equal, the correspnding elements can be splitted into another matrix. For example, i have the following matrix.
A = [ 1 2; 1 3; 1 4; 2 1; 2 4].
i want to get the following 2 matrices as the resulting matrices.
a1 = [2;3;4] and a2= [1;4]
i have just started learning the looping in MATLAB, your coperation will be highly appreciated.
Akzeptierte Antwort
Weitere Antworten (1)
Stephen23
am 22 Aug. 2016
Use accumarray:
out = accumarray(A(:,1),A(:,2),[],@(v){v})
1 Kommentar
pradeep kumar
am 22 Aug. 2016
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!