How to plot a function of two variables against one variable
Show older comments
I have a function z(x,y). I have set up an array for x and I need y=x^2. I've done that and set up the function but I cannot figure out how I am supposed to plot z against x. fplot doesn't work because I have more than one variable. What command should I use?
Answers (1)
Star Strider
on 6 Oct 2018
I am not certain what you want.
The documentation on the plot (link) function is an appropriate place to start. That page, and the links in it and at the end of it will eventually lead you to the correct approach. Then, when in doubt, experiment.
Explore these:
x = 1:10; % Create Data
y = x.^2; % Create Data
[X,Y] = meshgrid(x,y);
z = @(x,y) sin(x*2*pi/max(x(:))) .* cos(y*2*pi/max(y(:))); % Create Function
figure
surf(x, y, z(X,Y))
grid on
figure
plot(x, z(X,Y))
grid
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!