is there a way for a creation of variables for machine learning inside a loop from a dataset of waves

i have this dataset of wavelengths, problem is they are flipped and as such whenever i load the data i run a secondary part to rotate and flip, though so far i only have a way to read it and not really make use of it inside an ai machine learning thing
clc; clear; close all;
load('-mat','sub-036_task-eyesclosed_eeg.set','data','group','subject')
data_plot=flip(rot90(data,1));
N=width(data_plot);
B=height(data_plot);
figure
%----------------------- all of this is just for plotting and seeing it in stackedplot
T = array2table(data_plot, 'VariableNames',"CH: "+(1:N));
s = stackedplot(T);
s.AxesProperties(1);
ax = findobj(s.NodeChildren, 'Type','Axes');
set(ax, 'YTick', []);
%--------------------------
xlim([-500 B+500])
grid on
set (zoom(gcf), 'Motion', 'horizontal', 'Enable', 'on');
%--------------------------
i was wondering if there is a way to make like a for loop so in each loop i get data_1 then data_2 data_3 etc etc etc or how could i use a machine learning or signal labeler app or ai or artificial neural network and deal with the issue that i need to rotateflip the data?

2 Comments

"i was wondering if there is a way to make like a for loop so in each loop i get data_1 then data_2 data_3 etc etc etc "
The most important change is to always LOAD into an output variable:
S = load(..);
which you can then trivially loop over the fieldnames:
F = fieldnames(S);
for k = 1:numel(F)
A = S.(F{k});
.. do whatever with A
end
See also:

Sign in to comment.

Answers (1)

data_names = who('-file', 'sub-036_task-eyesclosed_eeg.set', '-regexp', '^data_\d+$');
for DNI = 1:length(data_names)
thisvar = data_names{DNI};
DS = load('-mat','sub-036_task-eyesclosed_eeg.set', thisvar);
data = DS.(thisvar);
%stuff
end

6 Comments

thank you for the reply, though this didn't seemed to work, what exactly it does?
The code certainly seems to work to me
SS.data_1 = [1 2 3];
SS.data_2 = [4 5 6];;
save('sub-036_task-eyesclosed_eeg.set', '-mat', '-struct', 'SS' );
whos -file sub-036_task-eyesclosed_eeg.set
Name Size Bytes Class Attributes data_1 1x3 24 double data_2 1x3 24 double
data_names = who('-file', 'sub-036_task-eyesclosed_eeg.set', '-regexp', '^data_\d+$');
for DNI = 1:length(data_names)
thisvar = data_names{DNI};
DS = load('-mat','sub-036_task-eyesclosed_eeg.set', thisvar);
data = DS.(thisvar);
%stuff
disp(data)
end
1 2 3 4 5 6
The code locates all of the data_ variables in the .set file. It loads them one by one into the variable data from where you can do <whatever> with them.
data_plot=flip(rot90(data,1));
I have to wonder whether that is correct code, or if instead the code should be
data_plot = flip(data.');
thank you so much for the answers, sorry for not replying earlier, and well the rot90 and flip is there because of how the data is organized from the openneuro site, which basically had the x and y inverted
x = [1 2 3 4];
y = [100 200 300 400];
data = [x; y];
data
data = 2×4
1 2 3 4 100 200 300 400
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
flip(data)
ans = 2×4
100 200 300 400 1 2 3 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
data.'
ans = 4×2
1 100 2 200 3 300 4 400
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
flip(data.')
ans = 4×2
4 400 3 300 2 200 1 100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
rot90(data,1)
ans = 4×2
4 400 3 300 2 200 1 100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
flip(rot90(data,1))
ans = 4×2
1 100 2 200 3 300 4 400
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
so data.' gives the same result as flip(rot90(data,1)).
Note that LOAD accepts a regular expression directly:
data = load('sub-036_task-eyesclosed_eeg.set', '-regexp','^data_\d+$');

Sign in to comment.

Categories

Products

Release

R2024a

Asked:

on 28 Nov 2024

Edited:

on 8 Dec 2024

Community Treasure Hunt

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

Start Hunting!