confusion about many, many workspace variables
4 views (last 30 days)
Show older comments
Hello all, I would like to know what I can do to concatenate or otherwise combine several items in my workspace. There are approximately 3840 samples, each is coded like: S01G1D2T3, S01G1T4....etc. Basically, there are 40 subjects, each with 96 trials. Each trial is a seperate item in the workspace. Some trials may have many more rows compared to others, but all have 36 columns of data.
Is there a way by which I can concatenate all trials, or perhaps a loop that will place each item into a matrix, but not requiring me to enter each item in sequence? Thanks a heap
0 Comments
Accepted Answer
More Answers (1)
Fangjun Jiang
on 15 Sep 2011
If you were given this data, you could do the following to improve the data structure so they are easy to handle.
save; % this saves the workspace to a default file called matlab.mat
D=load; % this loads the matlab.mat to the variable D
VarNames=fieldnames(D); % this will give you all the variable names
Then you could use a for-loop to concatenate the data. Assume all the data has 36 columns but different number of rows:
Data=[];
for k=1:length(VarNames)
Data=[Data;D.(VarNames{k})];
end
Data might grow large depending the size of your workspace data. Try some small amount of data first.
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements 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!