Filter löschen
Filter löschen

Extracting rows from a matrix based on values in columns

2 Ansichten (letzte 30 Tage)
Maria445
Maria445 am 8 Okt. 2017
Kommentiert: Maria445 am 8 Okt. 2017
Following on from this question
What if I have more than 1 column? That is, I want A to be a 6-by-4 matrix for example, so to have C{1} = 4-by-3 matrix?

Akzeptierte Antwort

Guillaume
Guillaume am 8 Okt. 2017
It's much easier to do this with the newer splitapply rather than the older accumarray:
A = [[1;1;3;2;3;1], rand(6, 3)]
C = splitapply(@(rows) {rows}, A(:, 2:end), A(:, 1))

Weitere Antworten (1)

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan am 8 Okt. 2017
for n=2:4, C_temp(:,n-1) = accumarray(A(:,1),A(:,n),[],@(n){n}); end
for m=1:size(C_temp,1), C{m} = cell2mat(C_temp(m,:)); end

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by