I can correct the error. Help me please!!

My code is:
x = linspace(-pi/2,pi/2,40);
y = x;
[X,Y] = meshgrid(x,y);
f = sin(X.ˆ2-Y.ˆ2);
figure(1)
contour(X,Y,f)
figure(2)
contourf(X,Y,f,20)
figure(3)
surf(X,Y,f)
the error is: ??? f = sin(Xˆ2-Yˆ2); |
Error: The input character is not valid in MATLAB statements or expressions.
How can I solve it?

 採用された回答

John Doe
John Doe 2013 年 5 月 9 日
編集済み: John Doe 2013 年 5 月 9 日

0 投票

This should work:
[X,Y] = meshgrid(x,y);
f = sin(power(X,2)-power(Y,2))
Hope it helps =)

3 件のコメント

Shaila parvin
Shaila parvin 2013 年 5 月 9 日
thanks thanks thanks a lot.............. it works........amazing
Shaila parvin
Shaila parvin 2013 年 5 月 9 日
this code outputs 3 images. these 3 images come one after another very quickly. i want to use an "enter" between each two output. i want: when i will run the code- the first image will be appear. when i'll press enter then the 2nd one will be seen. and so. how to do it?
John Doe
John Doe 2013 年 5 月 9 日
編集済み: John Doe 2013 年 5 月 9 日
You can use pause.
pause
Insert it in front of each line with figure

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

その他の回答 (1 件)

Wayne King
Wayne King 2013 年 5 月 9 日
編集済み: Wayne King 2013 年 5 月 9 日

0 投票

The problem is the character you have in for "^", not sure where you entered that in from, but copy and paste the below directly into the MATLAB workspace.
x = linspace(-pi/2,pi/2,40);
y = x;
[X,Y] = meshgrid(x,y);
f = sin(X.^2-Y.^2);
figure(1)
contour(X,Y,f)
figure(2)
contourf(X,Y,f,20)
figure(3)
surf(X,Y,f)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by