How to tabulate struct fields of cell arrays using nested for loops
Show older comments
How can i use a nested for loop to solve the following: I have 300x1 cell array with [1x1 struct] per cell. Each cell has the following:
struct with fields:
additional_model_information: ',AE2-60B,; ,AE2-60D,'
ceiling_fan_size_diameters_in_inches: '60'
airflow_efficiency_cfm_watt_low: '934'
airflow_efficiency_cfm_watt_high: '352'
The texts in the left (i.e of the structure fields) is the same for all 300 cells, but the right changes per brand name. How do i create a table that puts all that info together using a nested for loop?
1 Comment
Adam
on 14 Jul 2017
Can't you just use a 300x1 structure array instead of wrapping it in a cell array?
Answers (1)
Andrei Bobrov
on 14 Jul 2017
Edited: Andrei Bobrov
on 14 Jul 2017
Let a - your cell array.
names = fieldnames(a{1});
b = cellfun(@(x)struct2cell(x)',a,'un',0);
b = num2cell(cat(1,b{:}),1);
Tout = table(b{:},'V',names);
1 Comment
Mpho Moloi
on 14 Jul 2017
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!