Fill struct with an array
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Zarak Khan
il 21 Nov 2017
Risposto: Walter Roberson
il 21 Nov 2017
Hello,
I am facing difficulty in understanding on how to fill the struct within a for loop
for v=[-0.05, -0.03, 0.03, 0.05]
a=2+v;
s=struct('A',[],'B',[],'C',[],'D')
end
now what i want is the code to store individual values of 'a' in the struct means like 1.95 1.97 2.03 2.05 separately in the struct, instead of just the final value of 'a'
help would be great appreciated.
0 Commenti
Risposta accettata
Walter Roberson
il 21 Nov 2017
v=[-0.05, -0.03, 0.03, 0.05];
temp = num2cell(2+v);
names = {'A', 'B', 'C', 'D'};
S = cell2struct(temp, names, 2);
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!