Read csv files and save the plots (.bmp format)

조회 수: 2 (최근 30일)
Giggs B.
Giggs B. 2022년 3월 17일
편집: Giggs B. 2022년 3월 17일
Hi,
I have a code which reads data from all the csv files and converts them to wav files with the same name as the csv file in a different folder. What I want to do now is read all the csv files and save the time domain plots for each one of them with the same name as the csv file and in a different folder. How can I do that? Thanks.
clearvars
indir = '.'; %current directory
outdir = 'C:\Users\gagan\Downloads\testing_lab\Stage-1 testing\plots'; %where to write the results
files = dir( fullfile(indir, '*.csv'));
for file = files'
inname = fullfile(file.folder, file.name);
n = readmatrix(inname);
m = rescale(n, -1, 1, 'InputMin',2301,'InputMax',3642)+0.527;
[filepath,name,ext] = fileparts(inname);
outname = fullfile(outdir, name + ".wav");
%audiowrite(outname, m_filtered, 40000, 'BitsPerSample', 16);
%instead of audiowrite, make plots here and save the plots.
end

답변 (1개)

KSSV
KSSV 2022년 3월 17일
clearvars
indir = '.'; %current directory
outdir = 'C:\Users\gagan\Downloads\testing_lab\Stage-1 testing\plots'; %where to write the results
files = dir( fullfile(indir, '*.csv'));
for file = files'
inname = fullfile(file.folder, file.name);
n = readmatrix(inname);
m = rescale(n, -1, 1, 'InputMin',2301,'InputMax',3642)+0.527;
[filepath,name,ext] = fileparts(inname);
outname = fullfile(outdir, name + '.png');
plot(m) ; % use your variable in the plot
saveas(gcf,outname)
end
  댓글 수: 1
Giggs B.
Giggs B. 2022년 3월 17일
편집: Giggs B. 2022년 3월 17일
Hi KSSV,
Thanks for answering. However, I am unable to run this code. I get the below error. Any suggestion?
Arrays have incompatible sizes for this operation.
Error in automated_making_plots (line 11)
outname = fullfile(outdir, name + '.png');
I have posted a seperate question for this issue: Problem with saving plots - (mathworks.com)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by