[英]How to use inputdlg in meshgrid
这是表面网格图语法的例子:我希望中的变量meshgrid
用做inputdlg
并在方程z
变量。
[x,y] = meshgrid(-2:0.1:2);
z = x.*exp(-((x-y.^2).^2 + y.^2));
mesh(x,y,z)
一种可能有趣的解决方案是使用匿名函数。 可以使用函数str2func()
从字符串解析函数。 对话框中的字符数组可以使用str2double()
解析为整数。 根据拥有 Z 函数的数据点以及能够设置绘图密度/间隔的重要性,这可能是一个选择加入的选项。
概括:
• 使用匿名函数→ 在@()
定义的独立变量。
• 从对话框中获取输入变量。
• 使用fmesh()
在指定域上fmesh()
。
%Setting the prompts/field names%
Prompts = {'Axis Minimum','Axis Maximum','Function Equation'};
%Setting the dialog modal title%
Dialog_Title = 'Dialog Title: Change Me';
%Setting the dimensions of each input field%
Field_Dimensions = [1 50];
%Default Inputs/Placeholders%
Default_Inputs = {'-2','2','@(x,y)x.*exp(-((x-y.^2).^2 + y.^2))'};
%Grabbing the answers from the input dialog%
Answers = inputdlg(Prompts,Dialog_Title,Field_Dimensions,Default_Inputs);
%Grabbing the answers from the "Answers" array%
Axis_Minimum = str2double(Answers{1});
Axis_Maximum = str2double(Answers{2});
Z_Function = str2func(Answers{3});
%Plotting the function given the axis boundaries%
fmesh(Z_Function,[Axis_Minimum Axis_Maximum Axis_Minimum Axis_Maximum]);
使用MATLAB版本:R2019b
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.