How to write a structure variable in m file through another script?

How to write a structure variable in m file through another script? Eg. I want to write a structure like a.b.c in m file through script

7 个评论

Example: Let's say I have a file (Test.m) which has original following contents: a.b.c = 10; d.e = 20; x.y = 30;
From another script (Test_V2.m), I will evaluate the values of a.b.c, d.e & x.y as a.b.c = 1; d.e = 2; x.y =3;
These struct I want to update in original file Test.m How to do this?
"How to do this"
Learn to use functions (which are much better than scripts), and then simply pass those values are input/output arguments. Anything else is a waste of time (your time, and run-time).
This is a specific case when we need to update the m file by another script. NOTE: I already know how to do the same using functions.
Got the Solution myself. print as a string (Structures) into the *.m file.
If anyone has a better solution please let me know.
Post your solution too because it’s interesting
"If anyone has a better solution please let me know."
Convert to functions and pass the data as input/output arguments. This is "better" in the sense that it will be faster, will not impede the JIT engine, will be easier to debug, will allow memory management to handle the variables properly, and will be easier to understand. Printing strings in files is meta-programming, which is not recommended.
Functions are what experienced users use to write neat, efficient code. You should use them too.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Variables 的更多信息

产品

版本

R2010b

评论:

2018-10-29

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by