How can I plot the graph?
1 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Chunru
2021-9-16
x = 0:100;
plot(x,carFunc(x));
ylim([0 30])
function output = carFunc(x)
output = zeros(size(x));
idx = (x >= 75);
output(idx) = 25;
idx = (x < 75);
output(idx) = x(idx)/3;
end
2 个评论
Chunru
2021-9-17
"output=zeros(size(x));" allocates memory for the variable output and initializes it with 0s. This may make the code more efficient.
更多回答(1 个)
Behzad Eydiyoon
2021-9-16
function output = carFunc(x)
x=0:0.1:75;
if (x >= 75)
output = 25;
else
output = x/3;
end
plot(x,output)
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Scene Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!