Automatisation of struct creation and data import

4 views (last 30 days)
Dear all,
I created a 3x1 struct using folling code
data_alone_paired(1,1).name = 'pair#1_paired';
data_alone_paired(2,1).name = 'pair#2_paired';
data_alone_paired(3,1).name = 'pair#3_paired';
Subsequently, I filled the struct with data using acceleration data from motion analysis
Pair#1
data_alone_paired(1,1).acc_pelvis_subject1 = data_alone(1).fsignal_down(:,2);
data_alone_paired(1,1).acc_pelvis_subject2 = data_alone(2).fsignal_down(:,1);
Pair#2
data_alone_paired(2,1).acc_pelvis_subject1 = data_alone(3).fsignal_down(:,1);
data_alone_paired(2,1).acc_pelvis_subject2 = data_alone(4).fsignal_down(:,2);
Pair#3
data_alone_paired(3,1).acc_pelvis_subject1 = data_alone(5).fsignal_down(:,2);
data_alone_paired(3,1).acc_pelvis_subject2 = data_alone(6).fsignal_down(:,1);
Any suggestions how to automate this code using a loop?
Regards and thank you very much for your help.
Jonas
  2 Comments
Jonas Bender
Jonas Bender on 11 Aug 2022
Dear Matt,
thank you very much for your response. It was no typo. But your corretion makes it much more easier.
Jonas

Sign in to comment.

Accepted Answer

Matt J
Matt J on 9 Aug 2022
Edited: Matt J on 9 Aug 2022
for i=1:3
data_alone_paired(i,1).acc_pelvis_subject1 = data_alone(2*i-1).fsignal_down(:,1);
data_alone_paired(i,1).acc_pelvis_subject2 = data_alone(2*i).fsignal_down(:,2);
end
  1 Comment
Jonas Bender
Jonas Bender on 11 Aug 2022
Dear Matt,
your code works perfect. Thank you very much and regards.
Jonas

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!