When I try and plot this graph the figre comes up but no graph

 Respuesta aceptada

Andrew, it's there, just hard to see. Use instead
plot(a,f,'*b')

2 comentarios

This only gave me a specific point on the plot, I am looking for continuous plot. Thanks for your help.
Mischa Kim
Mischa Kim el 27 de Nov. de 2014
Editada: Mischa Kim el 27 de Nov. de 2014
Correct. You only get on point, since you can only call the function with a scalar variable a, e.g.
f(1)
and not a vector. In order to see more points on the plot you'd have to call the function repeatedly, using, for example, a loop:
for ii = 1:5
f(ii);
hold on;
end
Alternatively, you could do
function [f] = f (a)
a = a-3*floor(a/3);
f = 2*sqrt(a).*((0<=a) & (a<=1)) + (3-a).*((1<a) & (a<=3));
figure(1)
plot (a,f,'-b')
xlim([-6,6])
grid
end
and call the function with a vector input
f(0:1:10)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Nov. de 2014

Editada:

el 27 de Nov. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by