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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:26:54+00:00 2026-06-01T08:26:54+00:00

What is the syntax for declaring a global 2-dimensional array in MATLAB? I want

  • 0

What is the syntax for declaring a global 2-dimensional array in MATLAB?

I want the array to be blank, or uninitialized. That is, I want to be able to initialize it to some value later on using a for-loop. All the examples I have come across so far consist of initializing the array when it is declared. I find this rather tedious because my array might have to be a large one.

Thanks.

  • 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-01T08:26:56+00:00Added an answer on June 1, 2026 at 8:26 am

    Declare a variable as global first before using it:

    global my_glob_var;
    

    MATLAB doesn’t really support the concept of ‘uninitialised’ variables, but you can create an array of NaNs (not a number) to indicate that each value hasn’t been assigned yet. The arguments to the nan function indicate the size of the NaN array you wish to create:

    my_glob_var = nan(200, 200)
    

    There are other similar functions in case you wish to initialise arrays of zeros, ones, Inf etc.

    Then inside the functions you want to use it in, declare it as global again:

    function my_function
    
    global my_glob_var  % allows this function to use the global variable
    my_glob_var         % outputs the variable to command 
    

    As an aside, you note that you will “initialise it to some value later using a for-loop”. Depending on how you are initialising the array, there may be a vectorised way to achieve this (i.e. without using a for-loop). Vectorised operations are usually much quicker in MATLAB.

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

Sidebar

Related Questions

While coding a Map<>, I found out that declaring Map<int, int> is a syntax
EDIT: Sorry about ellipsis that's not what I actually have. For declaring an array
What is the VB.NET syntax for declaring the size of an array of objects
Does Java have any syntax for managing exceptions that might be thrown when declaring
Possible Duplicate: Declaring a function that return a 2D array in a header file?
I'm declaring a simple database class that includes an array of prepared statement, but
Today I've written simple test about syntax of declaring array, so, there are 3
What's the code syntax for declaring a subclass of EventHandler (that you've defined) in
Can anyone offered syntax for a sql query that takes an already created table
one of my favorite annoyance when coding in C++ is declaring some static variable

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.