Combine 2 Structures / have a nice weekend

1 次查看(过去 30 天)
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!

采纳的回答

Joseph Cheng
Joseph Cheng 2014-9-12
编辑:Joseph Cheng 2014-9-12
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.

更多回答(1 个)

Adam
Adam 2014-9-12
编辑:Adam 2014-9-12
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!

类别

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