【发布时间】:2017-03-04 00:24:33
【问题描述】:
我想为我的脚本制作简单的 GUI,我可以在其中编辑参数值并运行该脚本。
我用 2 个按钮创建了示例 scipt 和 GUI。我无法将脚本代码放入 GUI 代码中,我需要将它应用到更大的脚本上。
所以,脚本代码:
number = 10;
variable(1:10) = NaN;
for i = 1:10;
variable(i) = i * number;
end
figure
plot(variable)
按钮代码,工作正常。脚本是 .m 文件的名称,而不是函数:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
evalin('base','script')
但我不知道在编辑按钮代码中输入什么如果我想更改脚本中“数字”的值:
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
最后一件事,有时当我尝试绘制更多图形时,一个图形会覆盖 GUI 图,我只能看到按钮,但看不到整个 GUI。
感谢您的帮助。
【问题讨论】:
标签: matlab user-interface