problems with matrix splitting
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
pradeep kumar
am 22 Aug. 2016
Kommentiert: Azzi Abdelmalek
am 22 Aug. 2016
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.
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 22 Aug. 2016
Bearbeitet: Azzi Abdelmalek
am 22 Aug. 2016
A = [ 1 2; 1 3; 1 4; 2 1; 2 4]
[ii,jj,kk]=unique(A(:,1),'stable')
out=accumarray(kk,A(:,2),[],@(x){x})
celldisp(out)
4 Kommentare
Azzi Abdelmalek
am 22 Aug. 2016
I mean your question is not clear, why do you need a for loop, when accumarray can do the job?
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!