フィルターのクリア

Error Z must be a matrix, not a scalar or vector.

1 回表示 (過去 30 日間)
mohsen
mohsen 2016 年 3 月 5 日
編集済み: Walter Roberson 2016 年 3 月 5 日
prompt = 'what is the value of x';
prompt2 = 'what is value of y';
x = input(prompt);
y = input(prompt2);
u = 10*sin(200*x)+0.1*cos(10*y)+(100*x)/y;
[X,Y] = meshgrid(x,y);
Z = u
figure
mesh(Z)
Also, how would I use the element wise operator in this code?

採用された回答

Star Strider
Star Strider 2016 年 3 月 5 日
I prefer inputdlg to input, but that’s a personal preference and not a criticism of your code in that regard.
As best I can determine, you have your statements in the wrong order. Also, you need to define ranges for ‘x’ and y, not simply scalar values.
See if something like:
x = 1:10;
y = 20:30;
u = @(x,y) 10*sin(200*x)+0.1*cos(10*y)+(100*x)./y; % Create Anonymous Function From ‘u’
[X,Y] = meshgrid(x,y);
Z = u(X,Y);
figure(1)
mesh(X, Y, Z)
That works for me when I run it. The only changes I made in your code otherwise were to vectorise the division in ‘u’, to create a call to ‘u’ in your ‘Z’ assignment, and to add ‘X’ and ‘Y’ to your mesh call, because those tend to produce better (and more understandable) plots.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by