Indexing structured arrays

5 visualizaciones (últimos 30 días)
John Petersen
John Petersen el 24 de Mayo de 2012
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?

Respuesta aceptada

per isakson
per isakson el 24 de Mayo de 2012
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 comentarios
John Petersen
John Petersen el 24 de Mayo de 2012
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 el 24 de Mayo de 2012
Yes, I hesitated regarding row or column and forgot to comments on it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by