Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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
MATLAB gui中的导数?_Matlab_Function_User Interface_Plot_Derivative - Fatal编程技术网

MATLAB gui中的导数?

MATLAB gui中的导数?,matlab,function,user-interface,plot,derivative,Matlab,Function,User Interface,Plot,Derivative,我试图计算编辑文本框(edit1)的导数,并在静态文本框(text1)中显示答案。但它只是显示数字。我做错了什么 % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in

我试图计算编辑文本框(edit1)的导数,并在静态文本框(text1)中显示答案。但它只是显示数字。我做错了什么

% --- Executes on button press in pushbutton1.
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)
x=-10:.1:10;
equation = get(handles.edit1, 'String');
y = eval(equation);
derive_func = diff(y);
set(handles.text1, 'String', derive_func);
plot(y);
-
如您所见,它绘制函数,但在尝试区分时返回3行数字:

您看到重载函数的两种不同用法之间存在冲突
diff
。默认的内置用法是数值微分,您将函数应用于数值变量
y
,因此您将获得数值输出

您似乎想做的是使用符号数学工具箱中的
diff
来显示
5*x^4
,这要求您告诉matlab您想通过为diff提供正确的输入(通常是字符串)来使用符号数学工具箱

我正在使用MatlabR14,新版本的sym工具箱中有很多变化,但是下面的内容应该适合您

str = 'x^5';
diff(str,'x')
其中,
str
是要以符号方式区分的表达式。请注意,在我的版本中,sym工具箱对符号
x.^5
不满意,并且更喜欢
x^5
,我不知道它在MuPad上如何工作,但您可能需要找到一种解决方法,以确保为MuPad(或您正在使用的任何sym引擎)提供它可以处理的字符串

编辑


先前关于使用
cd
addpath
来控制使用哪个版本的重载函数
diff
的建议已被删除。

不要告诉人们他们需要将cd刻录到MATLAB工具箱目录才能使用它!这是非常糟糕的编程风格。搜索路径存在是有原因的。学习使用它。@woodchips一些澄清会很好:你建议的替代方案是什么。我尝试使用函数的完整路径进行str2fun,但在我的系统上,它没有像我链接到的答案中所显示的那样工作。你需要学习在matlab中使用路径。因此,pathtool、addpath、rmpath、savepath等。