필터 지우기
필터 지우기

Trying to replace num2cell with subasgn

조회 수: 1 (최근 30일)
Jacob Lynch August
Jacob Lynch August 2016년 1월 6일
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에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by