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

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 :)

 Risposta accettata

Star Strider
Star Strider il 3 Set 2012
Modificato: Star Strider il 3 Set 2012
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)

2 Commenti

Thanks a lot :) it helps greatly :)
It is my pleasure to help!

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by