EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • 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 Save Variable
 

Matlab Save Variable

Priya Pedamkar
Article byPriya Pedamkar

Updated June 22, 2023

Matlab Save Variable

 

 

Introduction to Matlab Save Variable

There are two operations in Matlab Save Variable which operate on file variables. One is the saved function, and the other is the load function. The save function saves the current working variable to a specific file. And load function is used to load the current working variable to a specific file. We must consider the workspace column to deal with the save and load functions. The workspace shows the total variables list along with the values in Excel sheets. Every time workspace automatically gets an update as we execute the program.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax:

  • Save filename: This syntax is used when all the current variables need to be stored in a specific file. (save file1), here save is the function, and file1 is the name of the file.
  • Save filename variable names: This syntax is used when limited or specific variables need to be stored in a file. ( save file1 v1, v2) , here save is a function and, file1 is the name of the file, and v1,v2 are variables.
  • Load file name: This syntax is used when all the current variables from the existing file must be loaded in a file. ( load file1 ), Here the load is a function, and file1 is the file’s name.
  • Load file name variables name: This syntax is used when limited or specific variables must be loaded in the file. (load file1 v1,v2) , here load is function and file1 is the name of the file and v1,v2 are variables

How does Save Variable work in Matlab?

There are two ways to save variables in Matlab. One way is using the ‘save workspace’ tab, and another is using the ‘save’ command. To save the variables in the file first method is very easy, in which first we need to declare variables and then need to assign the variables. After assigning the values, we must create one file to save the variables. By default, it will save all the variables in the file.

Steps to use the save function with default variables:

  1. Declare and assign variables ( v1, v2, v3 )
  2. Click on the save workspace tab
  3. Or use the save command ( save filename: save file 1 )

Steps to use the save function with variables:

  1. Declare and assign variables ( v1, v2, v3 )
  2. Click on the save workspace tab
  3. Or use the save command and mention variable names ( save filename variable 1, variable 2: save file 1 v1, v2 )

Steps to load functions with default variables:

  1. Clear workspace
  2. Use the load function ( load file 1 )

Steps to load functions with variables:

  1. Clear workspace
  2. Use the load function and mention variable names ( load file 1 v1,v2)

Examples of Matlab Save Variable

Examples of the following are given below:

Example #1

Let us consider one example with variables v1, v2, and v3; here values of v1 are 7, v2 is 4, and v3 is 9.

Code:

>> v1 = 7
>> v2 = 4
>> v3 = 9
> save file 1

Output:

matlab save variable

Code:

> clear
> load file1

Output:

matlab save variable

Code:

>> clear
>> load file1 v1 v2
>>

Output:

matlab save variable

Example #2

Consider the second example with variables var1, var 2, var 3, and var 4. Here var 1 and var 2 are input variables, and var3 and var 4 are output variables.

Code:
>> clear
>> var1 = 30
>> var2 = 65
>> var3 = var1 + var2
>> var4 = var1 - var2
>> save file2

Output:

matlab save variable

Code:

>> clear
>> load file2

Output:

load file2

Code:

>> clear
>> load file2 var3 var4
>>

Output:

load file2 var3 var4

Conclusion

The function ‘save’ and ‘load’ are essential functions in Matlab to handle the file variables. With the help of the save function, we store the variable values and data permanently in the machine so that we can use the values anytime in any program throughout the programming.

Recommended Articles

This is a guide to Matlab Save Variable. Here we discuss the introduction, how to save variable works in Matlab, and examples. You can also go through our other related articles to learn more–

  1. Natural Log in Matlab
  2. Arrays in Matlab
  3. Matlab colorbar Label | How to Work? | Examples
  4. Matlab Count | Examples | How to Work?
  5. Examples of fminsearch in Matlab

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
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - 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
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
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 Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW