How to output a cell array as a table where the arrays contain vectors of different length?
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
L'O.G.
el 6 de Mayo de 2023
Editada: Atsushi Ueno
el 6 de Mayo de 2023
I have a cell array C that is 3 x 10, with each element containing a vector of numbers of type double. Each vector is of a different length. How do I make a table where the first column is C{1,1}, the second column is C{1,2}, and so on?
0 comentarios
Respuesta aceptada
Star Strider
el 6 de Mayo de 2023
V1 = randn(5,1)
V2 = randn(10,1)
C = {V1 V2}
T = cell2table(C)
T{:,1}{:}
T{:,2}{:}
The iundividual variables remain cell arrays, so there is no problem with their not having the same internal dimensions.
.
0 comentarios
Más respuestas (1)
Atsushi Ueno
el 6 de Mayo de 2023
Editada: Atsushi Ueno
el 6 de Mayo de 2023
C = cell(3,10); % cell array C that is 3 x 10 with each element containing a vector of numbers of type double.
C = cellfun(@(x) rand(randi(10),1),C,'uni',false) % Each vector is of a different length. This is sample data.
C = reshape(C',1,[]); % reshape the cell array from 3 x 10 to 1 x 30 (row priority)
max_len = max(cellfun(@length,C)); % get the longest vector length
for k = 1:size(C,2)
C{k} = [C{k}; NaN(max_len-size(C{k},1),1)]; % fill each vector with missing to have the longest vector length
end
M = cell2mat(C);
T = array2table(M) % How do I make a table where the first column is C{1,1}, the second column is C{1,2}, and so on?
0 comentarios
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!