Trying to replace num2cell with subasgn

1 次查看(过去 30 天)
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 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by