How to tabulate struct fields of cell arrays using nested for loops
Afficher commentaires plus anciens
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
Adam
le 14 Juil 2017
Can't you just use a 300x1 structure array instead of wrapping it in a cell array?
Réponses (1)
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
Mpho Moloi
le 14 Juil 2017
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!