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 8757979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:25:57+00:00 2026-06-13T14:25:57+00:00

I am having a very strange issue with global variables in Matlab. Usually, when

  • 0

I am having a very strange issue with global variables in Matlab.

Usually, when you declare a variable to be global before assigning any value to it, it will be left as an empty variable. I have a variable R which I want to declare as global. But after I type clear and global R, in the variable list R is already set to be a 1*18 array, with some zero’s and other numbers filled in it.

I do have some other functions and scripts which share the global variable R, but I made sure I did not call any of the scripts or functions after I typed clear, and the variable list is already empty when I typed global R from the prompt.

enter image description here

But still, the problem persists. I guess I must have some serious misunderstanding of the rules about global variables. Can anybody explain why this is happening?

Thanks in advance.

  • 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-13T14:25:59+00:00Added an answer on June 13, 2026 at 2:25 pm

    The clear command does not clear global variables. It removes the variable from your local workspace, but it is still there. So if you assigned some value to it previously, declaring it again simply ‘shows’ the global variable in your local scope. You have to use clear all or clear global. From the documentation of clear:

    If variable name is global, then clear removes it from the current workspace, but it remains in the global workspace.

    Consider the following example:

    >> clear all; 
    >> global v;
    >> v = 1:100;  % assign global variable
    >> whos        % check if it is there
    
      Name      Size             Bytes  Class     Attributes
    
      v         1x100              800  double    global    
    
    >> clear;
    >> whos       % nothing declared in local workspace
    >> global v;
    >> whos       % ups, v is not empty!!
    
      Name      Size             Bytes  Class     Attributes
    
      v         1x100              800  double    global    
    
    >> clear global;     % you have to clear it properly
    >> whos
    >> global v          % now it is empty
    >> whos
      Name      Size            Bytes  Class     Attributes
    
      v         0x0                 0  double    global    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a very strange issue with Python's subprocess.Popen. I'm using it to call
Hey internets. I am having a VERY strange issue in C. I am deriving
hello fellow java developers. I'm having a very strange issue. I'm trying to read
Having a very strange issue regarding postback in ASP.NET. I have page dynamically populating
I am having a very strange issue with stat.h At the top of my
Having a very strange issue with a few creative banners. On some computers when
I'm having a very strange issue with a space invaders game I'm working on.
I'm having some troubles with displaying a graph. It's a very strange issue, because
I'm having a very strange issue, it looks like my application can't create file
I am having a very strange issue in an activity using a listview that

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.