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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:18:09+00:00 2026-06-09T16:18:09+00:00

I do have a simple question, but it doesn’t go for me. I want

  • 0

I do have a simple question, but it doesn’t go for me.
I want to preallocate a structure that contains many fields. I want to obtain it like this:
structure S 1×30 and each of 30 fields should be a structure 1×50 (some of 50 entries integers, some cells with strings, some subarrays). Is this possible to preallocate it without giving the exact names for each of 50 fields?

cheers!

  • 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-09T16:18:10+00:00Added an answer on June 9, 2026 at 4:18 pm

    AFAIK struct fields must be named, however, those names don’t need to be hard coded.

    For example if I have a struct foo that has a field named bar I can access that field like so:

    name = 'bar';
    data = foo.(name);  % the same as data = getfield(data, name);
    

    The foo.(name) notation indicates that one can make field names from variables (dynamic field names) for which the doc can be found here.
    Additionally you can use this to create fields.

    name = 'bar'
    for i = 1:10
      nameI = [bar, num2str(i)] ;
      foo.( nameI) = []; % the same as foo = setfield(foo, nameI, []);
    end
    

    The struct foo now has 10 fields named bar1, bar2, … bar10.

    If you absolutely don’t want names and simply want indicies then what you probably want is a cell array. Cell arrays are like regular matlab vectors except that they can contain anything.

    c = {'1234', 1234, [1 2 3 4],  [1 2; 3 4], @disp, {1 ,2, 3}};
    

    For example c is a cell array that contains a string, scalar, vector, matrix and then function handle, and another cell array.

    You can access the contents of an individual cell using the curly braces {}. So
    c{1} would return '1234' whereas c{2} would return a number.

    You could use either of these methods to pre-allocate a data structure that fits what you’ve described.

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

Sidebar

Related Questions

I have a simple question, but I'm about 80% sure that the answer to
may be too simple groovy question but....please help i have a list like this:
I have a simple question. Of course it has many answers but I cannot
Probably a simple question but one that eludes me nonetheless. I have a class:
I have a simple question but was not able to find an answer on
I have a what seems to be a simple question but for the life
Okay this may be a simple question but I have yet to come with
I have what I think is a simple question but I can't get it
I have a simple question, but searching on the internet didn't help me (maybe
I have a simple question, but I'm searching for longer time, but I always

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.