copy matrix to struct array

1 次查看(过去 30 天)
DF
DF 2017-2-3
回答: Stephen23 2017-2-3
I have a struct array as following:
M(1).x = ones(5,5);
M(2).x = ones(5,5);
M(3).x = ones(5,5);
and a matrix
A = magic(5);
which I would like to copy to all 3 elements of the struct array (replacing the values in the 'x'-field) without using a for loop. How can I do that?
Thank you in advance!
  1 个评论
DF
DF 2017-2-3
I think I figured it out: it's function 'deal' I was looking for.

请先登录,再进行评论。

回答(1 个)

Stephen23
Stephen23 2017-2-3
[M.x] = deal(A)

类别

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

产品

Community Treasure Hunt

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

Start Hunting!

Translated by