Indexing structured arrays

조회 수: 3 (최근 30일)
John Petersen
John Petersen 2012년 5월 24일
I have a two structures that have identical fields, but different lengths. I want to append part of one structure to the other. This works for a single element, but I want to vectorize it. I have tried
Struct1(i:i+n).parm1 = Struct2(k:k+n).parm1;
where i is the length of Struct1 and k and k+n are integers that lie within Struct2 length. However, I get the error "Insufficient outputs from right hand side to satisfy comma separated list expansion on left hand side. Missing [] are the most likely cause."
How do I make this kind of assignment without writing a for loop?

채택된 답변

per isakson
per isakson 2012년 5월 24일
Have you tried
new_struct = cat( Struct1(i:i+n), Struct2(k:k+n) );
Are the fields in the same order? Try this
[ Struct1(i:i+n).parm1 ] = [ Struct2(k:k+n).parm1 ];
  댓글 수: 2
John Petersen
John Petersen 2012년 5월 24일
Thanks! I needed to slightly modify your answer to include the dimension of concatenation in the cat() function, but that worked. I couldn't get the second option to work for me.
per isakson
per isakson 2012년 5월 24일
Yes, I hesitated regarding row or column and forgot to comments on it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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