How to assign a particular value to each element of a structure array for a particular field?
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Farzaneh
le 5 Avr 2015
Commenté : Mohammad Abouali
le 6 Avr 2015
Lets say I have a structure array (S) with n elements and with a field (f). I know I can use function "deal" to assign the same value to all elements of S.f, e.g. [S.f] = deal(zero) will assign zero to all the n elements of S.f
However, what I am looking for is to assign a particular value to each element of S.f; e.g. is there a way to assign each element of r=rand(1,n) to the corresponding element in S.f, i.e. S(i).f = r(i)?
Thanks.
0 commentaires
Réponse acceptée
Mohammad Abouali
le 5 Avr 2015
Modifié(e) : Mohammad Abouali
le 5 Avr 2015
n=3;
%initilizing some test structure
s=struct('f',cell(n,1));
% generate r vector
r=mat2cell(rand(1,n),1,ones(n,1));
% now dealing r to s.f
[s.f]=deal(r{:});
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Performance and Memory dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!