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

2 visualizaciones (últimos 30 días)
Giggs B.
Giggs B. el 17 de Mzo. de 2022
Editada: Giggs B. el 17 de Mzo. de 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

Respuestas (1)

KSSV
KSSV el 17 de Mzo. de 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 comentario
Giggs B.
Giggs B. el 17 de Mzo. de 2022
Editada: Giggs B. el 17 de Mzo. de 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)

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by