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 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 28 日
Example?
Partha Mitra
Partha Mitra 2018 年 10 月 28 日
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?
Stephen23
Stephen23 2018 年 10 月 28 日
"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).
Partha Mitra
Partha Mitra 2018 年 10 月 28 日
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.
Partha Mitra
Partha Mitra 2018 年 10 月 29 日
Got the Solution myself. print as a string (Structures) into the *.m file.
If anyone has a better solution please let me know.
madhan ravi
madhan ravi 2018 年 10 月 29 日
Post your solution too because it’s interesting
Stephen23
Stephen23 2018 年 10 月 29 日
"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 ExchangeVariables についてさらに検索

製品

リリース

R2010b

質問済み:

2018 年 10 月 28 日

コメント済み:

2018 年 10 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by