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

 Akzeptierte Antwort

Mischa Kim
Mischa Kim am 27 Nov. 2014
Andrew, it's there, just hard to see. Use instead
plot(a,f,'*b')

2 Kommentare

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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 27 Nov. 2014

Bearbeitet:

am 27 Nov. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by