Trying to replace num2cell with subasgn
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to avoid using num2cell when assigning data between arrays and structs.
%%e.g. data
A = rand(5,4,3)
B = rand( size( X ) )
%%e.g. output
s = struct( 'f1', 0, 'f2', 0' )
S = repmat( s, size( A ) )
%%current method
A = num2cell( A )
B = num2cell( B )
[ S(:).f1 ] = A{:}
[ S(:).f2 ] = B{:}
The code above is what I'm doing currently, but feel that there's a smarter way of accomplishing this. I have several custom scripts that rely on subsref but haven't mastered when it comes to structured variables. The data I have typically has more dimensions than the three I've listed, and I'd like a more general way (faster, using less memory) than the num2cell. I've searched around Mathworks and StackExchange but haven't found the magic set of keywords related to my goal.
Any insights on what I'm doing wrong would be appreciated.
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Structures 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!