How to save matlab plot automatically into a folder as a JPG
Show older comments
Hello I have csv data file and I am plotting it but I need to save this plot as JPG into a folder automatically, how can I do that ?

13 Comments
Atsushi Ueno
on 17 Apr 2021
Following code will save this plot as JPG into current folder automatically.
saveas(gcf,'plot.jpg');
Onur Hakverdi
on 17 Apr 2021
Atsushi Ueno
on 17 Apr 2021
Would you please check if your current folder is able to access or not?
Onur Hakverdi
on 17 Apr 2021
Onur Hakverdi
on 17 Apr 2021
Atsushi Ueno
on 17 Apr 2021
> How can I check ?
I am not sure if MATLAB has any method for checking file permission.
Similar question about access permission:
Onur Hakverdi
on 17 Apr 2021
Edited: Onur Hakverdi
on 17 Apr 2021
Atsushi Ueno
on 17 Apr 2021
If you mean you want to specify current folder.
pwd
If you want to change your current folder
cd C:\Users\Dowloand\
If you want to specify absolute foler path.
cd C:\Users\Dowloand\
saveas(gcf,'plot.jpg');
Or,
saveas(gcf, 'C:\Users\Dowloand\plot.jpg');
Similar Q&A: How to define a path in saveas command? - MATLAB Answers - MATLAB Central (mathworks.com)
Atsushi Ueno
on 17 Apr 2021
How did you solve the error below? I don't feel good if I don't know the cause.
Cannot create output file '.\plot.jpg'.
Onur Hakverdi
on 17 Apr 2021
Onur Hakverdi
on 17 Apr 2021
Onur Hakverdi
on 15 Jun 2021
Answers (1)
Shivang Srivastava
on 21 Apr 2021
As per my understanding you wanted to save a plot as a jpg file into a folder. I tried to reproduce the error you are facing but the error was not reproducible at my end.
data = csvread('test.csv');
wavelength = data(:,1);
intensity = data(:,2);
plot(wavelength, intensity);
ylabel('wavelength');
xlabel('intensity');
title('wavelength-intensity');
saveas(gcf,'C:\test.jpg','jpg')
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!