Structure Assginment
8 次查看(过去 30 天)
显示 更早的评论
I need a better approach to assign matrix to a structure. Currently I have
A = 5 by 1 struct with Loc & Err variables, A(1:5).Loc & A(1:5).Err,
I have Values matrix 5 by 6 where Loc info stored.
My code;
for i=1:5
A(i).Loc = Values(i,:)
end
Is there easy way of assignment. I have a very complex structure, this is very simplified version of it. Any ideas??
1 个评论
采纳的回答
Walter Roberson
2012-5-8
Try this:
vcell = mat2cell(Values, ones(1, size(Values,1)), size(Values,2));
[A.Loc] = vcell{:};
4 个评论
更多回答(1 个)
Jan
2012-5-8
There is no easy way to assign a very complicated structure.
Using a loop is most likely the easiest and most efficient method, especially if you use implicite pre-allocation by running the loop from the end to the start.
0 个评论
另请参阅
类别
在 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!