EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign up
Home Data Science Data Science Tutorials Matlab Tutorial Matlab Saveas

Matlab Saveas

Updated June 7, 2023

Matlab Saveas

Introduction of Matlab Saveas

In some applications, there is a need to save the output figure file to do further operations like data reading and data analysis from an output file to reference the output figure file. To save a figure to a specific file, we use a saveas statement. SAVEAS is an inbuilt function available on matlab for save the figure to specific file format. We can save the figures in different formats like png, jpg, epsc, etc.

ADVERTISEMENT
Popular Course in this category
MATLAB Course Bundle - 5 Courses in 1 | 3 Mock Tests

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax:

The syntax for Matlab saveas functions as shown below:-

saveas(fig,filename)
saveas(fig,filename,formattype)

How to Do Matlab Saveas?

The saveas function saves an image with a specific file format, formats like .png, .jpg, and many more. So for this function, we have syntax, as we saw above. For using a saveas function, first, we want to create an image; for creating an image, we use a bar function, the bar is an inbuilt function available on matlab, and the bar graph makes using the bar(x1) function with one bar for each element in x1. If x1 is a y-by-z matrix, then the bar creates y groups of z bars. Or we can create an image using a plot function; the plot is also an inbuilt function available on matlab. The plot is used to draw a continuous line and figure like an analog signal. Then this figure is saved using a saveas function. For saving this created image, we take saveas in parenthesis gcf; then we take a file name with a figure extension. Let us assume we take ‘Barchart11’ as a name with the extension .png, and we also specify the format type in the ‘formattype’ argument.

Examples of Matlab Saveas

Following are the examples are given below:

Example #1

Let us see an example for a saveas statement; the saveas function is an inbuilt function available on a matlab; it is used to save figures to a specific format. In this example, we create a bar chart; for creating a bar chart, we take data in variable x1. We take a bar chart data in a square bracket, a space separates each data number, and these data are assigned to a variable x1. Then we use a bar function available on matlab, an inbuilt matlab function. The bar graph creates using the bar(x1) function with one bar for each element in x1. If x1 is a y-by-z matrix, then the bar creates y groups of z bars. Then this generated bar graph is saving in .png format using a saveas function. We take saveas function in the parenthesis, gcf, then a file name with a figure extension. In this example, we take ‘Barchart11’ as a name with the extension .png. We save a figure in .png format.

Code:

clc ;
clear all;
close all;
x1 = [5 8 6 7 9 1 0.5 6 7 6 2 4 3 11 1 2];
bar(x1);
saveas (gcf,'Barchart11.png')

Output:

Example 1.1

Example #2

Let us consider an example for the saveas function; we create a figure in this example. For creating a figure, we use a plot; the plot is an inbuilt function available on matlab for creating a continuous signal of provided data. We take two variables, x, and y, for plotting data. In the x variable, we specify a range of 1 to 20 with a difference of 1. In the y variable, we take data that we plot on the x-axis. Then we use a plot(x, y) to generate a figure we want to save using a saveas function. We save this figure as an EPS file and use the epsc command to save it in color format. In the parenthesis, we take gcf. To save a current figure, we must specify fig as gcf, then take a file name, ‘Barchart1’, and specify the format type ‘formattype’ to epsc. In the EPS file, we save a figure.

Code:

clc;
clear all;
close all;
x = 1:1:20;y = [5 3 8 7 5 15 2 6 7 9 20 1 8 9 6 12.5 4 2 3 9];plot (x,y);
saveas (gcf, 'Barchart1', 'epsc')

Output:

Matlab Saveas-1.2

Example #3

Let us see another example of a saveas statement; in this, we create a bar chart, and we take data in variable y1 for a bar chart. Now we can take the data’s positive and negative integer values and plot the bar graph. We use the bar function to plot the bar graph, which is available on Matlab. Then the generated bar is save in jpg format using saveas statement. We save a figure in the jpg file.

Code:

clc;
clear all;
close all;
y1 = [-5 8 -6 7 -6 18 0.59 6.0 7 -6 2 4 -3 11 -1 2];
bar (y1);
saveas (gcf, 'Bargraph.jpg')

Output:

Matlab Saveas-1.3

Conclusion

In this article, we saw the concept of saveas matlab function; saveas is used to save figures to specific file formats. Then saw syntax related to saveas statements and how it is used in matlab code. Also, we saw some examples related to saveas statement and its output on matlab.

Recommended Articles

We hope that this EDUCBA information on “Matlab Saveas” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. Matlab plot title
  2. fplot() in Matlab
  3. Matlab Syms
  4. Matlab Sort
ADVERTISEMENT
SPSS Course Bundle - 14 Courses in 1 | 5 Mock Tests
34+ Hours of HD Videos
14 Courses
5 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
63+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
HADOOP Course Bundle - 32 Courses in 1 | 4 Mock Tests
125+ Hour of HD Videos
32 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
INFORMATICA Course Bundle - 7 Courses in 1
47+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Blog as Guest
Courses
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW