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

2 visualizzazioni (ultimi 30 giorni)
Giggs B.
Giggs B. il 17 Mar 2022
Modificato: Giggs B. il 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

Risposte (1)

KSSV
KSSV il 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 Commento
Giggs B.
Giggs B. il 17 Mar 2022
Modificato: Giggs B. il 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)

Accedi per commentare.

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by