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

2 Ansichten (letzte 30 Tage)
Giggs B.
Giggs B. am 17 Mär. 2022
Bearbeitet: Giggs B. am 17 Mär. 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

Antworten (1)

KSSV
KSSV am 17 Mär. 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 Kommentar
Giggs B.
Giggs B. am 17 Mär. 2022
Bearbeitet: Giggs B. am 17 Mär. 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)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by