Surf() Question

I'm trying to plot the results from an ethernet simulation, but I'm getting an error when I reach the surf() command. Everything else seems to be correct in the code.
Here is how I call the function:
%outputs
U=(frame_cntr.*10)./10000;
wt=find(waiting_time ~= -1);
ave_wait=sum(wt)./frame_cntr;
[n,p]=meshgrid(N,P);
surf(n,p,U)
surf(n,p,ave_wait)
and here is the error I'm getting:
??? Error using ==> surf at 70
Z must be a matrix, not a scalar or vector.
Error in ==> Telecomm_Main at 157
surf(n,p,U)
Any help is appreciated!

Answers (2)

Wayne King
Wayne King on 27 Apr 2012
U=(frame_cntr.*10)./10000;
The above must be a vector, but in order to use surf(), this must be a matrix.
For example:
Z = randn(100,1);
surf(Z)
Will generate the exact error you are getting.
If you want a 3-D plot of a vector, you can use plot3()
Walter Roberson
Walter Roberson on 27 Apr 2012

0 votes

You have not shown us any definition for N or P, so we have no idea what their sizes are relative to U. You have not given us any size hints for frame_cntr so we are not able to figure out the size of U (which would be the same as the size of frame_cntr).
Are you sure that frame_cntr is not a scalar when you run? frame_cntr would have to be a 2D matrix for everything else to work out dimensionally .

1 Comment

Paloma
Paloma on 27 Apr 2012
Yeah I double checked and my U and average_wait time are coming out as scalars, so I've gotta figure out where that is going wrong.
Thanks!

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Asked:

on 27 Apr 2012

Community Treasure Hunt

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

Start Hunting!