MATLAB App Designer 应用程序可以启动保存图形的脚本吗?
Can a MATLAB App Designer app launch a script which saves figures?
App Designer doesn't support saveas, savefig, or print,但是有没有办法用它来启动 MATLAB 程序呢?
我正在使用一个 MATLAB 程序,它有数千行代码,不是我的全部。该程序保存图形供以后参考,一些为 .fig 格式,一些为 PDF。它运行良好,但每个 运行 都有很多选项可供选择,目前通过编辑主脚本顶部的值来完成。我想添加一个 GUI 来简化它。
我知道还有其他方法,但 App Designer 似乎是 "modern" 要使用的东西。我可以将它用作现有脚本的启动器吗?如果我只是如下所示调用它,App Designer 的图形限制适用于整个脚本,它会执行所有计算但在第一个 "print" 处失败。我希望有另一种方式。
% Callback function
function GoButton_2Pushed(app, event)
% Save values for GUI restart.
setKeySaveState(app);
% Use a struct to pass values to the model.
scriptVars = app.modelVars;
% Run
The_Name_of_My_Script
end
我可以让 GUI 将结构写入 json 格式的文件,手动启动主脚本,然后让它读取文件。但这似乎很愚蠢。
编辑:这是来自 MATLAB 命令的错误消息 window:
Error using print (line 79) Functionality not supported with figures
created with the uifigure function. For more information, see Graphics
Support in App Designer.
Error in MapsCoralCoverClean>oneMap (line 298)
print('-dpdf', '-r200', outFile);
Error in MapsCoralCoverClean (line 70) oneMap(13, activeLatLon(:, 1),
activeLatLon(:, 2), events85_2010(activeReefs), [], jet, tName,
outFile, false);
Error in A_Coral_Model_170118 (line 780)
MapsCoralCoverClean(fullMapDir, Reefs_latlon, toDo, lastYearAlive, ...
Error in ModelGUI_2017a/GoButton_2Pushed (line 465)
A_Coral_Model_170118 Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback
(line 310) Error while evaluating Button PrivateButtonPushedFcn.
我发现最好的做法是始终显式提供图形对象的句柄,因为依赖 MATLAB 的 current figure and current axes 通常不一致并可能导致问题。
除非明确提供,否则 print
will save the current figure according to the other parameters passed. In this case, your uifigure
window is remaining the current figure during execution of your other processing functionality, causing print
to error out because it is not yet implemented for some of the new graphics objects (why, MathWorks, why!?). To fix this, pass the output of your processing functions' figure
调用作为 print
的第一个输入。
App Designer doesn't support saveas, savefig, or print,但是有没有办法用它来启动 MATLAB 程序呢?
我正在使用一个 MATLAB 程序,它有数千行代码,不是我的全部。该程序保存图形供以后参考,一些为 .fig 格式,一些为 PDF。它运行良好,但每个 运行 都有很多选项可供选择,目前通过编辑主脚本顶部的值来完成。我想添加一个 GUI 来简化它。
我知道还有其他方法,但 App Designer 似乎是 "modern" 要使用的东西。我可以将它用作现有脚本的启动器吗?如果我只是如下所示调用它,App Designer 的图形限制适用于整个脚本,它会执行所有计算但在第一个 "print" 处失败。我希望有另一种方式。
% Callback function
function GoButton_2Pushed(app, event)
% Save values for GUI restart.
setKeySaveState(app);
% Use a struct to pass values to the model.
scriptVars = app.modelVars;
% Run
The_Name_of_My_Script
end
我可以让 GUI 将结构写入 json 格式的文件,手动启动主脚本,然后让它读取文件。但这似乎很愚蠢。
编辑:这是来自 MATLAB 命令的错误消息 window:
Error using print (line 79) Functionality not supported with figures created with the uifigure function. For more information, see Graphics Support in App Designer.
Error in MapsCoralCoverClean>oneMap (line 298) print('-dpdf', '-r200', outFile);
Error in MapsCoralCoverClean (line 70) oneMap(13, activeLatLon(:, 1), activeLatLon(:, 2), events85_2010(activeReefs), [], jet, tName, outFile, false);
Error in A_Coral_Model_170118 (line 780) MapsCoralCoverClean(fullMapDir, Reefs_latlon, toDo, lastYearAlive, ...
Error in ModelGUI_2017a/GoButton_2Pushed (line 465) A_Coral_Model_170118 Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 310) Error while evaluating Button PrivateButtonPushedFcn.
我发现最好的做法是始终显式提供图形对象的句柄,因为依赖 MATLAB 的 current figure and current axes 通常不一致并可能导致问题。
除非明确提供,否则 print
will save the current figure according to the other parameters passed. In this case, your uifigure
window is remaining the current figure during execution of your other processing functionality, causing print
to error out because it is not yet implemented for some of the new graphics objects (why, MathWorks, why!?). To fix this, pass the output of your processing functions' figure
调用作为 print
的第一个输入。