Assign multi-dimension array to data structure array without for-loop
6 次查看(过去 30 天)
显示 更早的评论
I want to remove for-loop in order to assign array to data structure array.
S(1:3) = struct('a', zeros(3,3));
tmp = random('Normal', 0, 1, 3, 3, 3);
for ie = 1:3
S(ie).a = tmp(:,:,ie);
end
Here, I want to obtain S(:).a without for-loop. In addition, S(:).a is updated sometimes.
Many Thanks!
回答(2 个)
Matt Fig
2011-5-4
For example:
clear T S
T = rand(3,3,3);
S(1:3) = struct('a', mat2cell(T,3,3,[1 1 1]));
isequal(T(:,:,2),S(2).a) % just to check...
0 个评论
Daehung Kang
2011-5-4
2 个评论
Matt Fig
2011-5-4
These are details you left out of your original question, and they change the outcome. I did, however, answer your original question...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!