For loop for SVM variable files

1 visualizzazione (ultimi 30 giorni)
I want to classify my data with SVM on MATLAB. I have a folder, this folder has 70 sub-folders. Each of the 70 sub-folders has three preprocessed .mat files(selected features). These three files are my predictor variables. My design matrix is in a .mat file. Inside the design matrix, there are 3 items, out of which I want to use 2 as my class variables.
Using fitcsvm or any other Matlab svm function, I'm trying to classify that the predictor variables Fall into one of the two classes.
How do write a for loop that runs through these subfolders so that X = the predictor variables and Y= the class variables.

Risposta accettata

Balaji Udayagiri
Balaji Udayagiri il 8 Lug 2022
Hi Monalisa
As per my understanding, you want to loop through the folders to read the predictor variables for the SVM.
D = dir; %folder that contains the 70 data folders
D = D(~ismember({D.name}, {'.', '..'}));
for i = 1:numel(D)
subD = D(i).name; %each data folder containing the 3 subfolders
for j = 1:numel(subD)
currD = subD(j).name; %folder of the individual predictor variable
fList = dir(currD); % list contains the files in the current directory
% here you can read the data into your input variables, Not sure how the data is present in the folder.
end
end
  1 Commento
Monalisa Chikezie
Monalisa Chikezie il 9 Lug 2022
Hi @Balaji Udayagiri, thank you for the swift response. I updated the question. Does this still hold with the updated question?

Accedi per commentare.

Più risposte (1)

Pamudu Ranasinghe
Pamudu Ranasinghe il 7 Lug 2022
I think you can use "datastore" function in matlab
You dont need to loop through the files use 'IncludeSubfolders' to 'true' in datastore function.
This will do your work

Categorie

Scopri di più su Electrophysiology in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by