How to rename an existing structure A by assigning it a name stored in a string
12 views (last 30 days)
Show older comments
Sorry, this is very basic, but I could not get the answer from previous posts:
How to rename an existing structure A by assigning it a name new_name stored in a string name_string?
How can I rename A to name_string?
Stephen23 on 15 Aug 2020
Edited: Stephen23 on 15 Aug 2020
" this is very basic..."
and the answer is also very basic: dynamically naming variables is one way that beginners force themselves into writing slow, complex, obfuscated, buggy, hard-to-debug code:
"... but I could not get the answer from previous posts"
I am very surprised that you could not find any information on this, expecially considering how this topic has been discussed thousands of times on this forum (I have probably read most of the related threads).
Mehmed Saad on 15 Aug 2020
You can use assignin for that purpose
A = struct('X',1,'Y',2)
struct with fields:
More Answers (0)
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!