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

  • Home
  • SEARCH
  • 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 237227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:24:31+00:00 2026-05-11T20:24:31+00:00

I have no idea what’s going on here. I’m using R2006b. Any chance someone

  • 0

I have no idea what’s going on here. I’m using R2006b. Any chance someone out there with a newer version could test to see if they get the same behavior, before I file a bug report?

code: (bug1.m)

function bug1
S = struct('nothing',{},'something',{});
add_something(S, 'boing');          % does what I expect
add_something(S.something,'test');  % weird behavior
end

function add_something(X,str)
    disp('X=');
    disp(X);
    disp('str=');
    disp(str);
end

output:

>> bug1
X=
str=
boing
X=
test
str=
??? Input argument "str" is undefined.

Error in ==> bug1>add_something at 11
    disp(str);

Error in ==> bug1 at 4
add_something(S.something,'test');

It looks like the emptiness/nothingness of S.something allows it to shift the arguments for a function call. This seems like Very Bad Behavior. In the short term I want to find away around it (I’m trying to make a function that adds items to an initially empty cell array that’s a member of a structure).

Edit:

Corollary question: so there’s no way to construct a struct literal containing any empty cell arrays?

  • 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-11T20:24:31+00:00Added an answer on May 11, 2026 at 8:24 pm

    As you already discovered yourself, this isn’t a bug but a “feature”. In other words, it is the normal behavior of the STRUCT function. If you pass empty cell arrays as field values to STRUCT, it assumes you want an empty structure array with the given field names.

    >> s=struct('a',{},'b',{})
    
    s = 
    
    0x0 struct array with fields:
        a
        b
    

    To pass an empty cell array as an actual field value, you would do the following:

    >> s = struct('a',{{}},'b',{{}})
    
    s = 
    
        a: {}
        b: {}
    

    Incidentally, any time you want to set a field value to a cell array using STRUCT requires that you encompass it in another cell array. For example, this creates a single structure element with fields that contain a cell array and a vector:

    >> s = struct('strings',{{'hello','yes'}},'lengths',[5 3])
    
    s = 
    
        strings: {'hello'  'yes'}
        lengths: [5 3]
    

    But this creates an array of two structure elements, distributing the cell array but replicating the vector:

    >> s = struct('strings',{'hello','yes'},'lengths',[5 3])
    
    s = 
    
    1x2 struct array with fields:
        strings
        lengths
    
    >> s(1)
    
    ans = 
    
        strings: 'hello'
        lengths: [5 3]
    
    >> s(2)
    
    ans = 
    
        strings: 'yes'
        lengths: [5 3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone have idea how can find available IP addresses in a network using any
if any have idea to pinch zoom,zoom in ,zoom out ,rotation(left & right),drag &
Any one have idea how can get TAG of facebook photos using FQL?
Do any one have idea for finding true direction using iPhone? I want to
Any one have idea about how to post on our Google+ Stream using Google+
Anyone have idea how to pass value from iPhone application to the REST-Webservice using
Any body have idea how to put controls dynamically in asp.net 3.5 ? if
I missed my workspace in which I was working. Any one have idea about
Anyone have any idea why my jQuery carousel is working fine at the bottom
Can any body have idea how to consume php soap web service that have

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.