Make a table from a structure
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Milton Logothetis
am 2 Jan. 2019
Beantwortet: Peter Perkins
am 2 Jan. 2019
Hi, I want to create a table from a structure that has n fields and I also want the fieldnames to be added as variable names. I have tried the following but I can't find a way to change the column when each field is added:
fnames = fieldnames(data); % get fieldnames
T = table; %assign table to T
for i = 1:length(fnames)
x_T = table(num2cell(getfield(data, fnames{i}))); %extract each field into a variable and convert it to a cell array
T = [T; x_T];
end
T.Properties.VariableNames = {fnames{1:i}};
Akzeptierte Antwort
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Tables 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!