How can I convert 2 column matrix to a cell array?
Ältere Kommentare anzeigen
Is there a convenient way to convert a 2 column matrix into a cell array (without using nested for loops if possible)?
The matrix looks like:

Can I make a matrix from the above matrix such that the rows and columns of the new matrix(or a cell array you can say) will be like you see below:
the empty cells can be NAN and the filled cells are the values of the 3rd column of the old matrix. Akzeptierte Antwort
Weitere Antworten (2)
Jay Vaidya
am 31 Dez. 2019
0 Stimmen
Andrei Bobrov
am 31 Dez. 2019
T = readtable('path\to\your\xls\file\matrix.xlsx','ReadVariableNames',0);
T.Var3 = str2double(T.Var3);
T = T(any(T{:,1:2} ~= 0,2),:);
M = T{:,:};
[i,g] = findgroups(M(:,2));
out = flip(accumarray([M(:,1),i],M(:,3)),1);
3 Kommentare
Jay Vaidya
am 31 Dez. 2019
Andrei Bobrov
am 31 Dez. 2019
T = readtable('C:\Octavework\forums\xls\matrix_v2.xlsx','Range','A:C','ReadVariableNames',0);
T.Var3 = str2double(T.Var3);
T = T(any(T{:,1:2} ~= 0,2),:);
M = T{:,:};
i = findgroups(M(:,2));
out = flip(accumarray([M(:,1),i],M(:,3)),1);
Jay Vaidya
am 31 Dez. 2019
Kategorien
Mehr zu Matrices and Arrays 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!



