필터 지우기
필터 지우기

copy matrix to struct array

조회 수: 3 (최근 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에서 Structures에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by