How to automatically import multiple column vectors into Matlab from multiple .csv files using Live Script and a For Loop?
Mostrar comentarios más antiguos
Hello, I'm a coding and generally computing aliterate. I've used Matlab to evaluate data for my experiments in the University and now I'm also using it at work. Normally I get a large set of .csv files which I can individually import into Matlab. Today I found a tool "Import Data" and I've been experimenting with it, but I can't find a way to "add" into the Live Script a "For Loop code" so that the Files will automatically be read one by one storing my data into column vectors (arrays) with the same name but different numbers. Example: Pol_X_W, Pol_X_I, where X can be 000, 005, 010, 015... and so on. And also reading it from the same files by those arbitraty X numbers. I have no clue how a computer works, so I really would need you to explain to me either how the computer itself processes that information, so that I can find extra information on that on the web and then figure out a coding method or maybe theres a generic solution I haven't tried out. More specifically I just need the computer to understand that X is a variable that has to run throu a list of numbers I want to choose within the "Live Script" of the Data Import Tool.
Here is what the Code looks like:
Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 2);
% Specify range and delimiter
opts.DataLines = [2, Inf];
opts.Delimiter = ",";
% Specify column names and types
opts.VariableNames = ["Pol_20_W", "Pol_20_I"];
opts.VariableTypes = ["double", "double"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Import the data
tbl = readtable("/Users/User/Downl/Po/Spectrum_pol_020.csv", opts);
Convert to output type
Pol_20_W = tbl.Pol_20_W;
Pol_20_I = tbl.Pol_20_I;
Clear temporary variables
clear opts tbl
The 20 could be 020 I don't mind, but I would like to put 'X' and make a list of all the posible X values and automatically go throu them... cuz they are like 80 files... Thank you so much for reading this.
2 comentarios
Benjamin Thompson
el 8 de Feb. de 2022
Can you post sample CSV files and more information about what kind of output you want?
Manuel Rodrigo Lomas Anza
el 9 de Feb. de 2022
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Environment and Settings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!