how to read multiple csv files and plot them together

I have 8 csv files. how can I plot multiple csv files in one figure that has the same x_axis and multiple y_axis. I need to skip alternate y_axis columns and then plot them. For example, I want to plot x,y0 from file_1 with x,y0 from file_2 and so on. until now i could write only the following programming,
f1=readtable('file_1.csv'); %Read file 1
d1=table2array(f1);
bias1=d1(:,1); % defining x_axis
[rows clmn]=size(d1);
index=1;
for i=2:2:130 %skipping y_axis column
data1(:,index)=d1(:,i);
index=index+1;
end

 Akzeptierte Antwort

KSSV
KSSV am 22 Mär. 2021
csvFiles = dir('*.csv') ;
N = length(csvFiles) ;
for i = 1:N
T = readtable(csvFiles(i).name) ;
% Do what ever you want
end
Note that table is a pretty neat format. You can access any column by using T.(1), T.(2) etc......

5 Kommentare

Thank you so much for the answer, it worked.
The code you sent me works fine but when i tried to skip one column it shows me error. I need to skip columns and then divide them with 200 but it always shows me error Can you please give it a look?
csvFiles = dir('*.csv') ;
N = length(csvFiles) ;
for i = 1:N
T = readtable(csvFiles(i).name) ;
d1 = table2array (T)
end
bias1=d1(:,1); % defining x
[rows clmn]=size(d1);
index=1;
for i=2:2:130 %skipping columns
data1(:,index)=d1(:,i);
index=index+1;
end
y2_data1=data1./200
Why you want to run a loop to skip columns..?
B = A(:,2:2:130) ;
Minions
Minions am 22 Mär. 2021
Bearbeitet: Minions am 22 Mär. 2021
because i used indexing, to keep the files data organized, and i need to plot them also. I donno if i can plot them without using indexing or not?
KSSV
KSSV am 22 Mär. 2021
You can.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Discrete Data Plots finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 22 Mär. 2021

Kommentiert:

am 22 Mär. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by