Creating a function to Import data into structures
Show older comments
Hello,
I am currently using an sdk to import data from a software we use in our lab. When I import the data, I bring it into matlab in structures arrays which have fields for each trial I import, and sub-fields for each marker. So the structure looks like this...
TrajX.trialname.marker_name (TrajX stands for trajectory in the x direction)
I wanted to write a function to import this data so as to down on the lines of code in the script. However I am running into an issue. When I define the output of my function to NOT include the trial name...
[TrajX] = Import_Data_Function(vicon,subject,trialname,firstframe,lastframe);
the data is imported just fine, but the first trial's data gets overwritten when I attempted to import the next trial's data. So I end up with only one field consisting of a single trial name
If I include the trial name in the output of my function...
[TrajX.(trialname)] = Import_Data_Function(vicon,subject,trialname,firstframe,lastframe);
the data is imported with a field for each trial name, but instead of a structure that consists of TrajX.trialname.marker_name, I get a structure that consists of TrajX.trialname.trialname.marker_name. Basically, there is a field for each trial name followed by another sub-field of the same trial name, then another sub-field for each marker name.
I'm not sure why this second method creates two fields/sub-fields for trial names when I only want one???
Any help on this would be greatly appreciated. I've attached the original script, function, and new script with function.
Thanks in advance.
2 Comments
Mathieu NOE
on 15 Mar 2023
hi
what is the way you want to have one or multiple files get organized in a data structure ?
Josh Tome
on 16 Mar 2023
Accepted Answer
More Answers (0)
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!