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

4 views (last 30 days)
Giggs B.
Giggs B. on 17 Mar 2022
Edited: Giggs B. on 17 Mar 2022
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

Answers (1)

KSSV
KSSV on 17 Mar 2022
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 Comment
Giggs B.
Giggs B. on 17 Mar 2022
Edited: Giggs B. on 17 Mar 2022
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)

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!