Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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中插入Bode Plot函数_Matlab_Matlab Guide - Fatal编程技术网

如何在MatlabGUI中插入Bode Plot函数

如何在MatlabGUI中插入Bode Plot函数,matlab,matlab-guide,Matlab,Matlab Guide,我正在创建一个GUI,它根据输入的数据绘制Bode图。我有以下代码,但它给了我一个错误,我不明白 function first_gui %This gui plots a bode plot from a %a Transfer function generated from the main plot %Create a figure with the plot and others pushbutons f = figure('Visible','on','Position',[360,

我正在创建一个GUI,它根据输入的数据绘制Bode图。我有以下代码,但它给了我一个错误,我不明白

function first_gui

%This gui plots a bode plot from a
%a Transfer function generated from the main plot

%Create a figure with the plot and others pushbutons
f = figure('Visible','on','Position',[360,500,600,400]);
hplot = uicontrol('Style','pushbutton','String','Plot','Position',[415,200,70,25],'Callback',@tf_Callback);

%Create an entering data to numerator
htext = uicontrol('Style','text','String','Entre com a função de transferência','Position',[320,350,250,15]);
hnum = uicontrol(f,'Style','edit','String','Enter TF numerator...','Position',[320,320,250,20]);

%Create an entering data to denominator
htext_2 = uicontrol('Style','text','String','Entre com a função de transferência','Position',[320,280,250,15]);
hden = uicontrol(f,'Style','edit','String','Enter TF denominator...','Position',[320,250,250,20]);

hfig = axes('Units','pixels','Position',[50,60,200,185]);

%Initialize the UI

f.Units = 'normalized';
hfig.Units = 'normalized';
hplot.Units = 'normalized';
hnum.Units = 'normalized';
hden.Units = 'normalized';

sys = tf(hnum,hden);

f.Name = 'Bode Plot';


%Function to plot Bode
function tf_Callback(source,eventdata)
    bode(sys)


end
end
空闲时出现以下错误:

使用tf时出错(第279行) “tf”命令的语法无效。键入“help tf”以了解更多信息

简单_图中的错误(第29行) sys=tf(hnum,hden)

未定义的函数或变量“sys”

简单绘图/tf\U回调中出错(第36行) 博德(系统)

计算uicontrol回调时出错


您看到的错误是由于调用失败,因此,
sys
从未定义。然后在回调(
tf_callback
)中,您尝试使用
sys
,但由于从未创建过它,因此无法找到它,因此出现第二个错误

那么,让我们看看您传递给
tf
的内容,看看它失败的原因。您通过了
hden
hnum
。您可以这样创建它们

hden = uicontrol('style', 'edit', ...);
hnum = uicontrol('style', 'edit', ...);
这将为变量
hden
分配一个MATLAB。这个对象本身可以用来定义它的属性。对于编辑框,属性包含框中实际键入的内容。因此,我怀疑您实际上想要传递给
tf
的是
hden
hnum
uicontrols的值,而不是句柄本身。因此,您必须自己获取值并将其转换为数字()

然后可以将这些值传递给
tf

sys = tf(hnum_value, hden_value);
现在这应该行了。但是,我相信您真正想要的是在用户单击“绘图”按钮时从这些编辑框中检索值。按照当前的方式,这些值只会被检索一次(当GUI启动时),因为它们位于回调函数之外。如果您希望他们在每次单击“绘图”按钮时获取用户提供的值,那么您需要将上述代码放入按钮回调(
tfu回调
)中

现在,每当用户单击按钮时,将从编辑框中检索值,
sys
将被计算,并将创建一个波特图

您可能需要在回调中添加一些额外的错误检查,以确保为
hden
hnum
输入的值有效,并将生成有效的绘图,还可能抛出警告()或错误(),以提醒用户他们选择了无效值

sys = tf(hnum_value, hden_value);
function tf_Callback(src, evnt)
    hden_value = str2double(get(hden, 'String'));
    hnum_value = str2double(get(hnum, 'String'));
    sys = tf(hnum_value, hden_value);

    bode(sys);
end