How to tabulate struct fields of cell arrays using nested for loops

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

Can't you just use a 300x1 structure array instead of wrapping it in a cell array?

Sign in to comment.

Answers (1)

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

Thank you Andrei, but there is an error in using "cat". (Also, it says dimensions of matrices being concatenated are not consistent.)

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Asked:

on 14 Jul 2017

Commented:

on 14 Jul 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!