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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:34:38+00:00 2026-06-01T10:34:38+00:00

I have a struct array called AnalysisResults , that may contain any MATLAB datatypes,

  • 0

I have a struct array called AnalysisResults, that may contain any MATLAB datatypes, including other struct arrays and cell arrays.

Then I have a string called IndexString, which is the index to a specific subfield of StructArray, and it may contain several indices to different struct arrays and cell arrays, for example:
'SubjectData(5).fmriSessions{2}.Stats' or 'SubjectData(14).TestResults.Test1.Factor{4}.Subfactor{3}'.

And then I have a variable called DataToBeEntered, which can be of any MATLAB datatype, usually some kind of struct array, cell array or matrix.

Using eval, it is easy to enter the data to the field or cell indexed by IndexString:

eval([ 'AnalysisResults.', IndexString, ' = DataToBeEntered;' ])

But is it possible to avoid using eval in this? setfield doesn’t work for this.

Thank you 🙂

  • 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-01T10:34:39+00:00Added an answer on June 1, 2026 at 10:34 am

    Well, eval surely is the easiest way, but also the dirtiest.

    The “right” way to do so, I guess, would be to use subsasgn. You will have to parse the partial MATLAB command (e.g. SubjectData(5).fmriSessions{2}.Stats) into the proper representation for those functions. Part of the work can be done by substruct, but that is the lightest part.

    So for example, SubjectData(5).fmriSessions{2}.Stats would need to be translated into

    indexes = {'.' , 'SubjectData',
               '()', {5},
               '.' , 'fmriSessions',
               '{}', {2},
               '.' , 'Stats'};
    indexStruct = substruct(indexes{:});
    AnalysisResult = subsasgn(AnalysisResult, indexStruct, DataToBeEntered);
    

    Where you have to develop the code such that the cell array indexes is made as above. It shouldn’t be that hard, but it isn’t trivial either. Last year I ported some eval-heavy code with similar purpose and it seemed easy, but it is quite hard to get everything exactly right.

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

Sidebar

Related Questions

I have a struct-array that contains details of different reports that can be run.
I have an array of structs called leaders. The struct class looks like this,
I have a struct called Ambigous, and inside the struct I have an array
I have a function that, when called, takes a struct Pieces* field from a
I have a struct called member . Within member I have a std::string array
I have a struct with a dynamic array inside of it: struct mystruct {
I have this function in C++: struct MyObject { } testAlgorithm(array<String^>^ algorithms, MyObject^ myObject)
I have an array of structs and one of the fields in the struct
I have an array of objects that have QTTime structs as attributes. The objects
I have a struct which has several arrays within it. The arrays have type

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.