Effacer les filtres
Effacer les filtres

Combine 2 Structures / have a nice weekend

1 vue (au cours des 30 derniers jours)
Max Müller
Max Müller le 12 Sep 2014
Modifié(e) : Joseph Cheng le 12 Sep 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!

Réponse acceptée

Joseph Cheng
Joseph Cheng le 12 Sep 2014
Modifié(e) : Joseph Cheng le 12 Sep 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.

Plus de réponses (1)

Adam
Adam le 12 Sep 2014
Modifié(e) : Adam le 12 Sep 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!

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by