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 commentaire

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

Connectez-vous pour commenter.

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 14 Juil 2017
Modifié(e) : Andrei Bobrov le 14 Juil 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 commentaire

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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Question posée :

le 14 Juil 2017

Commenté :

le 14 Juil 2017

Community Treasure Hunt

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

Start Hunting!

Translated by