How to save matlab plot automatically into a folder as a JPG

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

Following code will save this plot as JPG into current folder automatically.
saveas(gcf,'plot.jpg');
No it does not work for me Error using matlab.graphics.internal.name (line 112)
Cannot create output file '.\plot.jpg'.
Error in print (line 71)
pj = matlab.graphics.internal.name( pj );
Error in saveas (line 181)
print( h, name, ['-d' dev{i}] )
Error in csvdeneme (line 10)
saveas(gcf,'plot.jpg');
Would you please check if your current folder is able to access or not?
yeah it worked but how can I specificy this folder like C/Users/Dowloands like this.
no, the code worked I done something than It worked but I need to know how to specificy the file way. Like I would like save as in C users in dowloands section.
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');
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'.
I tried randomly thing then current folder became empty.
also I tried to specific folder Error using saveas (line 138)
Invalid or missing path: C:\Kullanıcılar\yeni\plot.jpg
Error in csvdeneme (line 10)
saveas(gcf, 'C:\Kullanıcılar\yeni\plot.jpg');
than I got this error.
cd C:\Users\Dowloand\
saveas(gcf,'plot.jpg'); this code solved my problem

Sign in to comment.

Answers (1)

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')
You can go through the following documentation for more information on saveas function.

Categories

Asked:

on 17 Apr 2021

Commented:

on 15 Jun 2021

Community Treasure Hunt

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

Start Hunting!