필터 지우기
필터 지우기

Combine 2 Structures / have a nice weekend

조회 수: 1 (최근 30일)
Max Müller
Max Müller 2014년 9월 12일
편집: Joseph Cheng 2014년 9월 12일
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