天天看點

matlab三維圖加上四維,matlab 3D+顔色的四維函數的作圖

函數f=f(x,y,z),x,y,z是三維坐标軸,要畫的圖中要以x,y,z為三個軸,嘗試用surf(x,y,z,f),出來的表面圖是用顔色表示了f的大小,為了更直覺一些,能不能同時通過表面起伏來表示f大小呢?

結合之前熱心朋友的幫助,寫了一個小的測試程式:

[theta,phi]=meshgrid(linspace(0,pi,50),linspace(0,2*pi,50));

z=cos(theta);

x=sin(theta).*cos(phi);

y=sin(theta).*sin(phi);

f=-1*((x.*y).^2+(y.*z).^2+(z.*x).^2);

surf(x,y,z,f)

出來的圖一:

然後:

[theta,phi]=meshgrid(linspace(0,pi,50),linspace(0,2*pi,50));

z=cos(theta);

x=sin(theta).*cos(phi);

y=sin(theta).*sin(phi);

f=-1*((x.*y).^2+(y.*z).^2+(z.*x).^2);

surf(sin(theta).*cos(phi).*f,sin(theta).*sin(phi).*f,cos(theta).*f,f)

出來的圖2:

我現在遇到的問題  就是

[theta,phi]=meshgrid(0:0.1:2*pi,0:0.1:2*pi);

t=0:0.01:0.62;

z=t.*cos(theta);

x=t.*sin(theta).*cos(phi);

y=t.*sin(theta).*sin(phi);

f=-1*((x.*y).^2+(y.*z).^2+(z.*x).^2);

surf(sin(theta).*cos(phi).*f,sin(theta).*sin(phi).*f,cos(theta).*f,f)

Error using surf (line 75)

Z must be a matrix, not a scalar or vector.rf(sin(theta).*cos(phi).*f,sin(theta).*sin(phi).*f,cos(theta).*f,f)

是不是要用循環來計算啊  怎麼樣才能讓矩陣維數一緻呢?  求指導啊

2015-3-4 21:52 上傳

matlab三維圖加上四維,matlab 3D+顔色的四維函數的作圖
matlab三維圖加上四維,matlab 3D+顔色的四維函數的作圖

圖一

matlab三維圖加上四維,matlab 3D+顔色的四維函數的作圖

2015-3-4 21:54 上傳

matlab三維圖加上四維,matlab 3D+顔色的四維函數的作圖
matlab三維圖加上四維,matlab 3D+顔色的四維函數的作圖

圖2

matlab三維圖加上四維,matlab 3D+顔色的四維函數的作圖