×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Create new name for a structure or variable

Create new name for a structure or variable

Create new name for a structure or variable

(OP)
Hi

I want to create new names for my structure, or if not possible, variables. I have the following problem:

A variable in a for-loop is to be a part in my structure name. This means that the structures chuold be named as; structure1, structure2 and so on.

Is there any way to this and to be able to store any kind of data into these structures?

I have earlier tried to make variables in the same way using the following;¨

for i=1:10 eval(['variable' num2str(i) '=' num2str(i)]); end

 but in this case it is not possible to store numerical data in any good way, only strings.

Does anyone have any idea on how to solve this?


Regards Mattias  

RE: Create new name for a structure or variable

You just have to remove your last num2str to be able to assign any kind of data to your variable.

CODE

eval(['variable' num2str(i) '= anyX']);
And if you want this variable to be part of a struct you only have to add the structname to the expression

CODE

eval(['structname.variable' num2str(i) '= anyX']);
In both cases the anyX variable can contain anything. A matrix, a cell, a string or a double, it doesn't matter what kind of datatype is stored in the variable.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now