function [p,yy1]=graph999()
f1=gcf();
x0=str2num(char(inputdlg('Enter x0','Enter parametr',2,{'0'},'on')));
if (x0<-2)|(x0>6)
msgbox('x0 should be between -2 and 6','Results')
else
y0=str2num(char(inputdlg('Enter y0','Enter parametr',2,{'0'},'on')));
if (y0<-5)|(y0>6)
msgbox('y0 should be between -2 and 6','Results')
else
k=str2num(char(inputdlg('Enter k','Enter parametr',2,{'0'},'on')));
p=cos(y)+x.*y;
yy1=ygr(x0,y0,k);
end
end
function yy=ygr(X,Y,k)
x=-2:0.5:6;
y=-5:0.5:6;
[X,Y]=ndgrid(x,y);
Z=(X^2).*sin(Y)+k;
surf(X,Y,Z);
yy=Z;
It doesn't work with error
Undefined function or variable 'y'.
Error in graph999 (line 15)
p=cos(y)+x.*y;
What should I do for correct working?

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 25 日
編集済み: madhan ravi 2018 年 11 月 25 日

0 投票

function graph999 %main function
f1=gcf();
x0=str2double(char(inputdlg('Enter x0','Enter parametr',2,{'0'},'on')));
if (x0<-2)|(x0>6)
msgbox('x0 should be between -2 and 6','Results')
else
y0=str2double(char(inputdlg('Enter y0','Enter parametr',2,{'0'},'on')));
if (y0<-5)|(y0>6)
msgbox('y0 should be between -2 and 6','Results')
else
k=str2double(char(inputdlg('Enter k','Enter parametr',2,{'0'},'on')));
[x,y]=ygr(k); %sub function call inside main function
end
end
function [x,y]=ygr(k) %subfunction definition
x=-2:0.5:6;
y=-5:0.5:6;
[X,Y]=ndgrid(x,y);
Z=(X.^2).*sin(Y)+k;
surf(X,Y,Z);
yy=Z;
end
end
example of surface created:

3 件のコメント

Mariya Shilovskaya
Mariya Shilovskaya 2018 年 11 月 25 日
編集済み: Mariya Shilovskaya 2018 年 11 月 25 日
You're the wizard! Thanks a lot!
Stephen23
Stephen23 2018 年 11 月 25 日
It is recommended to use str2double rather than str2num (which hides an eval call inside).
madhan ravi
madhan ravi 2018 年 11 月 25 日
編集済み: madhan ravi 2018 年 11 月 25 日
Anytime :) ,
Another easy way to produce surface:(requires symbolic toolbox)
syms x y
k=input('k value ? ')
ezsurf(x^2*sin(y)+k)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

製品

リリース

R2016a

質問済み:

2018 年 11 月 25 日

編集済み:

2018 年 11 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by