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월 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