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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:03:03+00:00 2026-05-26T07:03:03+00:00

I have a loop in MATLAB that fills a cell array in my workspace

  • 0

I have a loop in MATLAB that fills a cell array in my workspace (2011b, Windows 7, 64 bit) with the following entries:

my_array = 
    [1x219 uint16]
    [         138]
    [1x0   uint16] <---- row #3
    [1x2   uint16]
    [1x0   uint16]
    []             <---- row #6
    [         210]
    [1x7   uint16]
    [1x0   uint16]
    [1x4   uint16]
    [1x0   uint16]
    [         280]
    []
    []
    [         293]
    [         295]
    [1x2   uint16]
    [         298]
    [1x0   uint16]
    [1x8   uint16]
    [1x5   uint16]

Note that some entries hold [], as in row #6, while others hold [1x0] items, as in row #3.

  1. Is there any difference between them? (other than the fact that MATLAB displays them differently). Any differences in how MATLAB represents them in memory?
  2. If the difference is only about how MATLAB internally represents them, why should the programmer be aware of this difference ? (i.e. why display them differently?). Is it a (harmless) bug? or is there any benefit in knowing that such arrays are represented differently?
  • 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-05-26T07:03:04+00:00Added an answer on May 26, 2026 at 7:03 am

    In most cases (see below for an exception) there is no real difference. Both are considered “empty”, since at least one dimension has a size of 0. However, I wouldn’t call this a bug, since as a programmer you may want to see this information in some cases.

    Say, for example, you have a 2-D matrix and you want to index some rows and some columns to extract into a smaller matrix:

    >> M = magic(4)  %# Create a 4-by-4 matrix
    
    M =
        16     2     3    13
         5    11    10     8
         9     7     6    12
         4    14    15     1
    
    >> rowIndex = [1 3];  %# A set of row indices
    >> columnIndex = [];  %# A set of column indices, which happen to be empty
    >> subM = M(rowIndex,columnIndex)
    
    subM =
       Empty matrix: 2-by-0
    

    Note that the empty result still tells you some information, specifically that you tried to index 2 rows from the original matrix. If the result just showed [], you wouldn’t know if it was empty because your row indices were empty, or your column indices were empty, or both.

    The Caveat…

    There are some cases when an empty matrix defined as [] (i.e. all of its dimensions are 0) may give you different results than an empty matrix that still has some non-zero dimensions. For example, matrix multiplication can give you different (and somewhat non-intuitive) results when dealing with different kinds of empty matrices. Let’s consider these 3 empty matrices:

    >> a = zeros(1,0);  %# A 1-by-0 empty matrix
    >> b = zeros(0,1);  %# A 0-by-1 empty matrix
    >> c = [];          %# A 0-by-0 empty matrix
    

    Now, let’s try multiplying these together in different ways:

    >> b*a
    
    ans =
         []  %# We get a 0-by-0 empty matrix. OK, makes sense.
    
    >> a*b
    
    ans =
         0   %# We get a 1-by-1 matrix of zeroes! Wah?!
    
    >> a*c
    
    ans =
       Empty matrix: 1-by-0  %# We get back the same empty matrix as a.
    
    >> c*b
    
    ans =
       Empty matrix: 0-by-1  %# We get back the same empty matrix as b.
    
    >> b*c
    ??? Error using ==> mtimes
    Inner matrix dimensions must agree.  %# The second dimension of the first
                                         %#   argument has to match the first
                                         %#   dimension of the second argument
                                         %#   when multiplying matrices.
    

    Getting a non-empty matrix by multiplying two empty matrices is probably enough to make your head hurt, but it kinda makes sense since the result still doesn’t really contain anything (i.e. it has a value of 0).

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

Sidebar

Related Questions

In Matlab, I have a loop that performs operations on arrays. I would like
It is known that MATLAB works slow with for loop. I have tried to
I have a loop that reads each line in a file using getline() :
I have a loop on page to update an access database that takes 15-20
I have a loop that finds duplicate lines in a .ini file. I can
I have a loop that runs through a variety of websites and I'd like
I have a loop that runs for approx. 25 minutes i.e 1500 seconds. [100
I have a structure in matlab that has a value of <1x1 struct>. ,
I have an NxM matrix in MATLAB that I would like to reorder in
So, I have a cell-array of 1xN vectors of different lengths. I want to

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.