Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于MatlabGUI_Matlab_User Interface - Fatal编程技术网

关于MatlabGUI

关于MatlabGUI,matlab,user-interface,Matlab,User Interface,在MatlabGUI中,我想绘制:A*sin(x)。A是振幅。我创建了一个轴、一个按钮和两个编辑文本,一个是“振幅”,另一个是用户输入的“a”。 在编码部分,我不知道该怎么做。以下是我到目前为止所做的代码 function pushbutton1_Callback(hObject, eventdata, handles) plot(sin(0:.1:10)) function input_ampli_Callback(hObject, eventdata, handles) function

在MatlabGUI中,我想绘制:A*sin(x)。A是振幅。我创建了一个轴、一个按钮和两个编辑文本,一个是“振幅”,另一个是用户输入的“a”。 在编码部分,我不知道该怎么做。以下是我到目前为止所做的代码

function pushbutton1_Callback(hObject, eventdata, handles)
plot(sin(0:.1:10))

function input_ampli_Callback(hObject, eventdata, handles)

function input_ampli_CreateFcn(hObject, eventdata, handles)

input = str2num(get(hObject,'String')); 

if (isempty(input))
    set(hObject,'String','0')
end

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end 

你需要告诉Matlab在哪里绘制你的数据,在你的情况下,它在轴上

您显示的input_ampli_回调和input_ampli_CreateFcn不太可能用于您的特定用途。基本上,您只需要使用如下方式从用户处获取振幅:

A = str2num(get(handles.input_ampli,'String'));
function pushbutton1_Callback(hObject, eventdata, handles)

A = str2num(get(handles.input_ampli,'String'));

axes(handles.axes1) % This is the handles of the axes object. The name might be different. This is used to tell the GUI to make this axes the current axes, so stuff will be displayed in it.

plot(A*sin(0:.1:10)); Plot your function!
然后绘制函数。所以一切都可以在按钮回调中发生。因此,您的代码如下所示:

A = str2num(get(handles.input_ampli,'String'));
function pushbutton1_Callback(hObject, eventdata, handles)

A = str2num(get(handles.input_ampli,'String'));

axes(handles.axes1) % This is the handles of the axes object. The name might be different. This is used to tell the GUI to make this axes the current axes, so stuff will be displayed in it.

plot(A*sin(0:.1:10)); Plot your function!
当然,您可以在GUI中添加其他文本框,让用户选择要打印的范围,但原理是相同的。希望这能帮助你开始

编辑:以下是一个简单编程GUI的代码,您可以自定义和使用它来查看它是如何工作的。它不使用指南,但原则相同。我使用全局变量在不同函数(回调)之间轻松共享数据。希望这也有帮助

function PlotSin(~)

global ha hPlotSin htext hAmp
%  Create and then hide the GUI as it is being constructed.
f = figure('Visible','off','Position',[360,500,450,285]);

ha = axes('Units','Pixels','Position',[50,60,200,185]);

% Create pushbutton
hPlotSin = uicontrol('Style','pushbutton','String','Plot',...
    'Position',[315,220,70,25],...
    'Callback',{@Plotbutton_Callback});
% Create text box
htext = uicontrol('Style','text','String','Enter amplitude',...
    'Position',[325,90,60,30]);

% Create edit box to let the user enter an amplitude 
hAmp = uicontrol('Style','Edit','String','',...
    'Position',[325,50,60,30]);

% Assign the GUI a name to appear in the window title.
set(f,'Name','Simple GUI')
% Move the GUI to the center of the screen.
movegui(f,'center')
% Make the GUI visible.
set(f,'Visible','on');


end

% This is the pushbutton callback.
function Plotbutton_Callback(source,eventdata)
global ha hPlotSin htext hAmp

A = str2num(get(hAmp,'String')); % Get the amplitude

x = 0:0.1:10; % Define x...
axes(ha) % Make the axes the current axes so the function is plot in it.

plot(x,A*sin(x)) % Plot the data

end

你有一个复杂的家庭作业,让我们帮你做,对吗?问题对问题。。。这是你教授给你的密码,你没有表现出任何努力。提示:至少删除提示。无意冒犯,如果我的假设是错误的,我很抱歉。但是家庭作业问题和“请给我代码”在这里并不受欢迎。总是表现出自己的努力。离题:你的教授会知道这个网站,如果你用真名注册,可能不会有帮助;)哈哈,谢谢你的建议,听起来不错。这不是家庭作业。我已经解决了。