"I will say that I've written a verbose form of this code that sets variables for every import. I have 25 simulations with 20 seeds each to compare and its very error prone."
That is not a surprise, because your approach is one way that beginners force themselves into writing slow, complex, buggy code. The approach of "..creating some variable name that corresponds seed numbers...": magically creating/accessing variable numbers is the problem. Read this to know why:
Forcing meta-data into variable names is bad way to write code. Meta-data, like the sequential folder names, is data, so it should be stored as data and not forced awkwardly into variable names.
You should simply store the data in one array (e.g. a structure, or cell array, or an ND array) which is then trivial to access using efficient indexing. Here is something to get you started:
D = 'path to where the PATH* directories are located';
P = 'path1';
S = dir(fullfile(D,P,'seed*));
for jj = 1:numel(S)
F = fullfile(D,P,S(jj).name,'Ca_cyt.dat');
S(jj).data = csvread(F);
end
And that is all. The data for the files are all stored in the structure S, along with the folder names. So you can access them trivially using indexing, e.g. the second folder's name and data:
It also means that you can use a comma-separated list to perform actions on all of the imported data or filenames. For example, to put all of the filenames into one cell array:
or to vertically concatenate all of the imported data:
or you can access it in other ways, depending on the size and classes of your data.
Read this to know more about how comma separated lists work:
You might also want to look at the examples in the MATLAB documentation:
Because you did not upload any sample files or explain anything about them I have no idea how your data files are formatted, so you will have to pick the file importing function yourself. I just used csvread as an example. If you upload a sample data file then I could help you with picking a suitable data importing function.
"Lastly, I would like to compare the averages of different situations.... path1 ... path2 ... path3 ..."
Then you will probably have to put the entirety of my code into another loop, basically like this:
D = 'path to where the PATH* directories are located';
N = 3;
C = cell(1,N);
for ii = 1:N
P = sprintf('path%d',ii);
C{ii} = dir(fullfile(D,P,'seed*));
for jj = 1:numel(C{ii})
F = fullfile(D,P,C{ii}(jj).name,'Ca_cyt.dat');
C{ii}(jj).data = ...
end
end
And then access the structures inside the cell array C. You could generate one structure array from that cell array, which might make accessing the data easier:
Best Answer