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

 Risposta accettata

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

2 Commenti

This only gave me a specific point on the plot, I am looking for continuous plot. Thanks for your help.
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)

Accedi per commentare.

Più risposte (0)

Categorie

Richiesto:

il 27 Nov 2014

Modificato:

il 27 Nov 2014

Community Treasure Hunt

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

Start Hunting!

Translated by