Creating Table from Cell Array Data
Mostra commenti meno recenti
Hi All,
I am trying to create a table from data stored in a Cell array . The cell array is 1x3 specified as follows:
SelectNewVectorCell = {[1;2;3;4;5;6;9;88], [11;22;23;25;66;88], [33;55;66;7;8;9]};
I then try to create the table using the following code. Unfortunately, I can only get it to output the final column of the cell array to the table (it seems to be overwriting…)
le = length(SelectNewVectorCell)
names(1,1:le) = {'Bin1'};
rows1 = cellfun(@(M) size(M,1), SelectNewVectorCell);
cols1 = cellfun(@(M) size(M,2), SelectNewVectorCell);
maxrows1 = max(rows1)
R = table();
for K = 1 : length(SelectNewVectorCell)
R.(names{K}) = [SelectNewVectorCell{K}; nan(maxrows1 - rows1(K), cols1(K))];
end
Interestingly if I change the code slightly to this it seems to work
le = length(SelectNewVectorCell)
% names(1,1:le) = {'Bin1'};
names1 = {'Bin1', 'Bin2', 'Bin3'};
rows1 = cellfun(@(M) size(M,1), SelectNewVectorCell);
cols1 = cellfun(@(M) size(M,2), SelectNewVectorCell);
maxrows1 = max(rows1)
R = table();
for K = 1 : length(SelectNewVectorCell)
R.(names1{K}) = [SelectNewVectorCell{K}; nan(maxrows1 - rows1(K), cols1(K))];
end
Any ideas why the first code fails to write correctly to the table? Thanks
Ben
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Tables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!