Save arrays in a structure

30 次查看(过去 30 天)
Hi.
I have written an algorithm that computes an array "b" for each ith iteration [i={1,2,3,4}], and I would like to save those arrays in a structure called "A".
How to save those arrays in the structure "A" where its elements are function of "i", i.e, A = {b1, b2,b3, b4} and to get b1 for instance, one would have to type A.b1.
Regards.
  2 个评论
Stephen23
Stephen23 2019-5-16
编辑:Stephen23 2019-5-16
Note that using a non-scalar structure would be more efficient than generating fieldnames.
Indexing is much faster and less buggy than messing around forcing meta-data (i.e. that index) into some fieldnames.

请先登录,再进行评论。

采纳的回答

madhan ravi
madhan ravi 2019-5-15
doc cell2struct
  3 个评论
madhan ravi
madhan ravi 2019-5-16
编辑:madhan ravi 2019-5-16
A=struct; % an example
for k=1:5
A.(sprintf('b%d',k))=rand(5);
end
Abderrahmane DADA
Abderrahmane DADA 2019-5-16
Thanks a lot Madhan.
That's exactly what I was looking for.

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by