The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Dynamic Structure
Replies: 4   Last Post: Jan 8, 2014 10:02 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 4
Registered: 1/7/14
Dynamic Structure
Posted: Jan 7, 2014 1:46 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Good morning(afternoon or night),

I have a question that is more about optimising my MATLAB code. Don?t know if you can help.

% Say I have a predefined list of ratio IDs:

ratioID = [{'AA9';'AA10';'AB112'}];

% To use these IDs as variables in a dynamic structure and assigning a value of 1 to each, I do the following:

for k = 1:3,

struct.(ratioID{k}) = 1;


My question is whether it is not possible to assign the values to ID without having to use a for-loop? I would think something like struct.(ratioID{1:end}) = 1 should work, but it doesn?t.

My goal is to have a structure called ?struct?, with the fields ?AA9?, ?AA10? and ?AB112?, with each of these fields having a value of 1. In real life, the number of fields is much greater than 3, so

I won?t be able to enter the field names manually.

Thanks in advance

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.