简体   繁体   English

如何从MATLAB GUI将句柄写入.m文件?

[英]How do I write handles from a MATLAB GUI into a .m file?

I am trying to create a GUI for a script that receives paths and matrix names from the user (via uigetdir and uigetfile functions as well as edit text fields), and finally upon pushing the "Run" button writes these handles into a .m file and runs another script. 我试图为脚本创建一个GUI,该脚本从用户(通过uigetdir和uigetfile函数以及编辑文本字段)接收路径和矩阵名称,最后按“运行”按钮将这些句柄写入.m文件中并运行另一个脚本。 Essentially, in the end it should create a file called 'RunName'.m that looks something like: 从本质上讲,最后应该创建一个名为“ RunName” .m的文件,该文件如下所示:

base_path = get(handles.BasePathEdit,'String') base_path = get(handles.BasePathEdit,'String')

file_name = get(handles.FileNameEdit,'String') file_name = get(handles.FileNameEdit,'String')

main % runs the main script with the preceding variables defined as they were main%使用前面定义的变量运行主脚本

and run it. 并运行它。

I'm guessing the script would run successfully if I just write it like that under the 'Run' push-button function, but I would still like for it to create a .m file as described. 我猜想,如果我只是在“运行”按钮功能下编写脚本,脚本便可以成功运行,但是我仍然希望脚本能够按所述方式创建.m文件。

Thank you very much for you help, All the best. 非常感谢您的帮助,祝一切顺利。

The simplest way of accomplishing this is to write a function that executes upon the pressing of the 'run' button that reads the values from the GUI and the proceeds with the main script. 完成此操作的最简单方法是编写一个功能,该功能在按下“运行”按钮后执行,该按钮从GUI读取值并继续执行主脚本。 In guide, this is simple - right-click on the 'run' button, and under 'View Callbacks', select 'Callback'. 在指导中,这很简单-右键单击“运行”按钮,然后在“查看回调”下选择“回调”。 Then you can use the usual syntax get(handles.RELEVANT_TEXT_BOX,'string') etc to read the resr of the data in. You can then pass this to your main function, or you could then just copy and pase your script straight into the callback. 然后,您可以使用常规语法get(handles.RELEVANT_TEXT_BOX,'string')等读取数据的resr。然后可以将其传递给您的main函数,也可以直接将脚本复制并定位为打回来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM