For loop extracting variable
9 views (last 30 days)
I am trying to extract data from different data files. In each data file i have an amplitude that is different but want to pull out that data file and name it a different name for each time i run the loop.For example, i have four files names "lab_test_1, lab_test_2, lab_test_3, lab_test_4" and within each of these files i have a variable named 'amplitude'. Is it possible within a for loop to extract each amplitude renaming it to the lab # i pulled it out from? Example: "amplitude_1", "amplitude_2" and so on.
Peng Li on 13 Apr 2020
Not quite sure your data type. So below just a structure that you can potentially use.
within the for loop
for iF = 1:yourFileNumbers
% above stuff you need to load your data
% you get the amplitude
% and rename it
eval(['amplitude_' num2str(iF) ' = amplitude;']);
But actually people are against of generating many variables as it is loose and slow. Better make amplitude a field of your lab_test_ data using structure or table. You could easily access amplitude by dot indexing.