Combine 2 Structures / have a nice weekend
1 view (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Joseph Cheng
on 12 Sep 2014
Edited: Joseph Cheng
on 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.
0 Comments
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!