why cant i plot graph with surf() function?

2 views (last 30 days)
ernest
ernest on 27 Nov 2014
Commented: Image Analyst on 27 Nov 2014
clc;clear all;
for t=0:0.02:2
for x=0:0.1:10
U=10*sin(2*pi*(t-(x/5)))+2*sin(2*pi*(t+(x/5)))
end
end
  3 Comments
ernest
ernest on 27 Nov 2014
nope its not homework dont worry.just some random practice i find around
Image Analyst
Image Analyst on 27 Nov 2014
OK, no problem then. If my answer worked, can you officially mark it as "Accepted"? Thanks in advance.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 27 Nov 2014
Edited: Image Analyst on 27 Nov 2014
You didn't index U - it's just a single number. You can either index it, or vectorize it. I show the vectorized method below:
T = 0:0.02:2;
X = 0:0.1:10;
[t, x] = meshgrid (T, X);
U=10*sin(2*pi*(t-(x/5)))+2*sin(2*pi*(t+(x/5)));
surf(U);

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!