copy matrix to struct array

1 Ansicht (letzte 30 Tage)
DF
DF am 3 Feb. 2017
Beantwortet: Stephen23 am 3 Feb. 2017
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 Kommentar
DF
DF am 3 Feb. 2017
I think I figured it out: it's function 'deal' I was looking for.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 3 Feb. 2017
[M.x] = deal(A)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by