How to plot a surface 3d plot using this function?

1 次查看(过去 30 天)
TIME=1:1:100;
Z=1:1:100;
[X,Y]=meshgrid(TIME,Z);
P=12242-28.649.*cos(6.28.*TIME+1.33.*Z)-1702.3.*sin(6.28.*TIME+1.33.*Z)-495.13.*cos(12.57.*TIME+2.67*Z)+986.71.*sin(12.57.*TIME+2.67.*Z)+498.18.*cos(18.85.*TIME+4.*Z)-398.52.*sin(18.85.*TIME+4.*Z)-319.34.*cos(25.13.*TIME+5.33.*Z)+165.06.*sin(25.13.*TIME+5.33.*Z)+213.61.*cos(31.42.*TIME+6.67.*Z)-71.69.*sin(31.47.*TIME+6.67.*Z)-151.29.*cos(37.7.*TIME+8.*Z)+29.867.*sin(37.7.*TIME+8.*Z)+112.34.*cos(43.98.*TIME+9.33.*Z)-9.378.*sin(43.98.*TIME+9.33.*Z)-86.576.*cos(50.266.*TIME+10.667.*Z)-1.2438.*sin(50.266.*TIME+10.667.*Z);
surf(Z,P,TIME)
The error is always the same:
??? Error using ==> surf at 78 Z must be a matrix, not a scalar or vector.
Error in ==> signal at 5 surf(Z,P,TIME)
Can anybody help me on this?..Any help will be appreciated. THanks and have a nice day :)

采纳的回答

Star Strider
Star Strider 2012-9-3
编辑:Star Strider 2012-9-3
The easiest way to do what you want is to convert P into an anonymous function and pass it the correct arguments:
TIME=1:1:100;
Z=1:1:100;
[X,Y]=meshgrid(TIME,Z);
P=@(TIME,Z) 12242-28.649.*cos(6.28.*TIME+1.33.*Z)-1702.3.*sin(6.28.*TIME+1.33.*Z)-495.13.*cos(12.57.*TIME+2.67*Z)+986.71.*sin(12.57.*TIME+2.67.*Z)+498.18.*cos(18.85.*TIME+4.*Z)-398.52.*sin(18.85.*TIME+4.*Z)-319.34.*cos(25.13.*TIME+5.33.*Z)+165.06.*sin(25.13.*TIME+5.33.*Z)+213.61.*cos(31.42.*TIME+6.67.*Z)-71.69.*sin(31.47.*TIME+6.67.*Z)-151.29.*cos(37.7.*TIME+8.*Z)+29.867.*sin(37.7.*TIME+8.*Z)+112.34.*cos(43.98.*TIME+9.33.*Z)-9.378.*sin(43.98.*TIME+9.33.*Z)-86.576.*cos(50.266.*TIME+10.667.*Z)-1.2438.*sin(50.266.*TIME+10.667.*Z);
Pmtx = P(X,Y);
surfc(X,Y,Pmtx)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by