Combine 2 Structures / have a nice weekend

1 visualización (últimos 30 días)
Max Müller
Max Müller el 12 de Sept. de 2014
Editada: Joseph Cheng el 12 de Sept. de 2014
As you can see here, i am trying to combine two structures. It works ! But is there a faster way ?
Variable = length(OldInputData)
for k = 1:length(InputData)
OldInputData(Variable + k).shotnumber = InputData(k).shotnumber
OldInputData(Variable + k).UsedAmp = InputData(k).UsedAmp
OldInputData(Variable + k).ClosestAmp = InputData(k).ClosestAmp
OldInputData(Variable + k).OptimalAmp = InputData(k).OptimalAmp
OldInputData(Variable + k).Factor = InputData(k).Factor
OldInputData(Variable + k).ReadSSX = InputData(k).ReadSSX
OldInputData(Variable + k).ssx_t = InputData(k).ssx_t
end
Have a nice weekend!

Respuesta aceptada

Joseph Cheng
Joseph Cheng el 12 de Sept. de 2014
Editada: Joseph Cheng el 12 de Sept. de 2014
you can go
OldInputData = [OldInputdata InputData]
only if they contain the same structures inside. Since you're just concatenating it should work fine. if there is a new structure it'll add that to the others but be empty.
see example:
for i =1:10
old(i).shot = randi(10);
old(i).used = randi(10);
old(i).closest = randi(10);
old(i).optimal = randi(10);
old(i).factor = randi(10);
old(i).ssx= randi(10);
old(i).lkjasf = randi(10);
end
old = [old old]
then i can see that
i should be able to check that old(1) and old(11), 2 and 12, etc. should have the same stuff.
if we add a new structure element (is that the right term?) to it like
i = i+1;
old(i).shot = randi(10);
old(i).used = randi(10);
old(i).closest = randi(10);
old(i).optimal = randi(10);
old(i).factor = randi(10);
old(i).ssx= randi(10);
old(i).lkjasf = randi(10);
old(i).asdfasdf = 2
then all 1:20 has a new asdfasdf = [] to them.

Más respuestas (1)

Adam
Adam el 12 de Sept. de 2014
Editada: Adam el 12 de Sept. de 2014
I did something very similar myself just the other week, but since that seems to be a ready-built explanation of various methods there isn't much point me fishing out whatever method I ended up using!

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by