Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8008999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:18:55+00:00 2026-06-04T18:18:55+00:00

I have m file ( main.m ), and I have some variables that I

  • 0

I have m file (main.m), and I have some variables that I have in this file.

In the end of the file, I wrote: clear all

I want to clear all the variables. so in the Matlab, I wrote: main, in order to run the function.

When the function completes, I wrote in MATLAB console the name of one of the variables of main.m.

For example, I wrote the variable: data

Surprisingly, the variable exists.

Why the expression clear all doesn’t delete it?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:18:56+00:00Added an answer on June 4, 2026 at 6:18 pm

    Functions have their own variable scope. When you return from a function, all the local variables of the function are cleared and the variables and values that were present immediately before the function call are restored, the only difference being the return values of the function from which you just returned. You can easily follow this process by using MATLAB debugger, first make sure you have some variables defined in the first function, then step in to the second function (F11 at least in Linux version) and then step through the second function and finally step out the second function when you reach return or end of the function, and you’ll see that the local variables of the second function are cleared and the variables of the first function are restored.

    This means that you cannot clear the workspace variables inside a function, at the least not by using clear all, because inside a function clear all only clears all variables inside its variable scope.

    If you follow functional programming paradigm, usually you don’t need to worry about workspace variables, because all that matters is the variables you create and modify in your own functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a header file that has some static variables for all of my
I have a code that looks like this: int main () { fstream file;
I am working in C, and have some variables that I don't want to
I have a javascript file main.js and five html files 1.html,2.html,3.html,4.html,5.html I want to
I have a feeling I'm being stupid. Given this ini file: [main] source1 =
I do have a \res\layout\main.xml file. Yet, this: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
I have a file with a module with some routines that take parameters and
I must process some huge file with gawk. My main problem is that I
I have and external JS scripts file with all my objects in that runs
I have a xml file main.xml with following markup and data. main.xml <xml> <content>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.