confusion about many, many workspace variables

2 visualizaciones (últimos 30 días)
Alek
Alek el 15 de Sept. de 2011
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de Sept. de 2011

Más respuestas (1)

Fangjun Jiang
Fangjun Jiang el 15 de Sept. de 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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by