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

조회 수: 4 (최근 30일)
Andrew
Andrew 2014년 11월 27일
편집: Andrew 2014년 11월 27일
m

채택된 답변

Mischa Kim
Mischa Kim 2014년 11월 27일
Andrew, it's there, just hard to see. Use instead
plot(a,f,'*b')
  댓글 수: 2
Andrew
Andrew 2014년 11월 27일
This only gave me a specific point on the plot, I am looking for continuous plot. Thanks for your help.
Mischa Kim
Mischa Kim 2014년 11월 27일
편집: Mischa Kim 2014년 11월 27일
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)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by