How to create a plot for multiple CSV files in a loop?

5 ビュー (過去 30 日間)
Theo McCarthy
Theo McCarthy 2022 年 10 月 10 日
コメント済み: VBBV 2022 年 10 月 10 日
I have 24 CSV files and for each of them I'd like to create a figure with 6 subplots (ie 24 figures each with 6 subplots) . The subplots are just one column of the csv files plotted against the first column (time). I'd like to use a loop to do this so it can be done automatically. The first 12 rows of the csv files need to be ignored.
I have tried using
csvFiles = dir("*.csv");
N = length(csvFiles);
for i = 1:N
fid = fopen('csvFiles(i)')
data = txtscan(fid,'Delimiter',',','Headerlines',12)
but txtscan is not recognised.
I have also tried using
fid = fopen('csvFiles(i)')
data = csvread(csvFiles(i).name,'Headerlines','12')
followed by
C0 = data(:,1);
C1 = data(:,2);
C2 = data(:,3);
C3 = data(:,4);
C4 = data(:,5);
C5 = data(:,6);
C6 = data(:,7);
subplot(6,1,1)
plot(C0, C1)
hold on
subplot(6,1,2)
plot(C0, C2)
hold on
subplot(6,1,3)
plot(C0, C3)
hold on
subplot(6,1,4)
plot(C0, C4)
hold on
subplot(6,1,5)
plot(C0, C5)
hold on
subplot(6,1,6)
plot(C0, C6)
hold on
But this has also not worked.

回答 (1 件)

VBBV
VBBV 2022 年 10 月 10 日
textscan(fid,'Delimiter',',','Headerlines',12)
  3 件のコメント
Theo McCarthy
Theo McCarthy 2022 年 10 月 10 日
I'm struggling at how to open the csv files one by one in each loop. In the first loop how do I ensure it is the first csvFile that is opened and the data is extracted from and then make sure it's the second file in the second iteration etc
VBBV
VBBV 2022 年 10 月 10 日
Attach the CSV data file

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by