MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [求助]看看我的程序错在哪里 (https://www.labfans.com/bbs/showthread.php?t=4916)

huanghuan 2008-10-19 21:17

[求助]看看我的程序错在哪里
 
给出一任意空间粒子的密度分布函数 n=f(x,y,z)=cos(z)*exp[-(x^2+y^2)/4],画出空间粒子密度的梯度场及等密度面。x、y的范围是[-2:0.5:2],z的范围是[0:0.5:4].
我的程序如下:
clear
>> x=-2:0.5:2;
>> y=x;
>> z=0:0.5:4;
>> [X,Y,Z]=meshgrid(x,y,z);
>> n=cos(Z).*exp(-(X.^2+Y.^2)/4);
>> [pX,pY,pZ]=gradient(n);
>> contour3(n);
??? Error using ==> contourc
Contour data must have 2 dimensions.

Error in ==> D:\MATLAB6p5\toolbox\matlab\specgraph\contours.m
On line 57 ==> CS=contourc(varargin{numarg_for_call});

Error in ==> D:\MATLAB6p5\toolbox\matlab\specgraph\contour3.m
On line 80 ==> [c,msg] = contours(varargin{1:nin});

meteora1005 2008-10-19 22:04

回复: [求助]看看我的程序错在哪里
 
contour3的输入矩阵必须是二维的,但你的n是三维矩阵,如果改为:
contour3(n(:,:,1));%n的第一页,n共有9页
倒是能画出图来,但不知是不是符合你的要求。


所有时间均为北京时间。现在的时间是 11:13

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.