Hi there
I am having trouble trying to create a script that will open up all .csv files in a subfolder and then save each of those as a .mat file. I have a few hundred of these individual .csv files and find it much easier to analyse information in matlab when the data is a .mat file so am trying to find a way to speed up the process rather than using the small code I have and having to select the individual file each time. If I want to change just one file I use the following that I generated from the import tool in Matlab (which works). Each of the files have the same number of variables and the same variable names. I'm hoping someone is able to help me figure out how to loop this so that it will run through all the files. I have read the help information in Matlab on for loops and have searched in Matlab Answers for help, but I have not been able to figure this out myself and would really appreciate any assistance.
%Import options
opts = delimitedTextImportOptions("NumVariables", 4);
% Specify range and delimiter
opts.DataLines = [3, Inf];
opts.Delimiter = ",";
% Specify what the column names are and what the variable types are.
opts.VariableNames = ["Time", "Displacement", "Force", "TensileStress"];
opts.VariableTypes = ["double", "double", "double", "double"];
% Specify file level properties
opts.ExtraColumnsRule = 'ignore';
opts.EmptyLineRule = 'read';
% Import the data from the file named
SLC11_1 = readtable("C:\Users\krist\OneDrive\Documents\MATLAB\SLC11_1.csv", opts);
% This will show the read .csv file as a table and then save it in the .mat format
SLC11_1 = table2array(SLC11_1);
save('SLC11_1.mat')
0 Comments
Sign in to comment.