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

 採用された回答

Mischa Kim
Mischa Kim 2014 年 11 月 27 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeLine Plots についてさらに検索

質問済み:

2014 年 11 月 27 日

編集済み:

2014 年 11 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by