Effacer les filtres
Effacer les filtres

Creating Table from csv files.

6 vues (au cours des 30 derniers jours)
Raushan
Raushan le 25 Juil 2022
Commenté : Chunru le 25 Juil 2022
I have 5 csv files in a folder. all these csv files have multiple column with names like x,y,u,v....
I want to plot all u (In this case total 5 u will be there from five csv file) values in Matlab.
I am able to read and extract the column that contain u value from these csv files but not able to store it in array so that i can plot them on the same axis.
Can you please help!
Any help will be appreciated!
my code is
Folder='C:\Users\user\Desktop\7-19-22'
mat = dir(fullfile(Folder, '*.csv'));
disp(mat)
for files_i = 1:length(mat)
disp(mat(files_i).name)
data = fullfile(Folder,mat(files_i).name);
ReadCSV(data,files_i);
end
arr [];
function s = ReadCSV(data,i)
opts = detectImportOptions(data)
opts.SelectedVariableNames = {'u'};
T = readtable(data,opts);
disp(T)
end

Réponse acceptée

Chunru
Chunru le 25 Juil 2022
Folder=pwd; %'C:\Users\user\Desktop\7-19-22'
mat = dir(fullfile(Folder, '*.csv'));
uall = [];
for files_i = 1:length(mat)
data = fullfile(Folder,mat(files_i).name);
x = readtable(data);
uall =[uall x.u];
end
plot(uall)
  3 commentaires
Raushan
Raushan le 25 Juil 2022
@Chunru How you got the plots. When I ran the same code I am not getting any plots.
Chunru
Chunru le 25 Juil 2022
Use your own folder name where data files are stored:
Folder='C:\Users\user\Desktop\7-19-22'

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by