If I have something like
A(1).a = {c};
A(2).a = {d};
and
B(1).a = {e};
B(2).a = {f};
and want to assign B.a to A.a,
for i=1:length(A)
A(i).a = B(i).a;
end
is there a way to do this without doing a 'for' loop?

 채택된 답변

추가 답변 (1개)

John BG
John BG 2016년 1월 29일

0 개 추천

A.a and B.a are type struct. How do you expect to be able to assign B.a=A.a without making sure that the structures have same fields?
The obvious solution is that you build a function, kind of assignstruct(struc1,struc2) and that in this function you first make sure you can copy data from one structure to the other, and if struct1 struct2 are not compatible then return error.
John

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2016년 1월 28일

답변:

2016년 1월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by