y=(1/4)t*sin(2t)
I am getting a straight line with this code t = [0, .1, 50]; y = .25.*(t).* sin(2*(t)); figure; plot(t,y); xlabel('t'); ylabel('y'); title('A function')
but I am not sure why is is wrong

 采纳的回答

Use colons (:) instead of commas to create ‘t’:
t = 0 : 0.1 : 50;
y = 0.25*(t) .* sin(2*t);
figure
plot(t,y)
In MATLAB, colons create a vector. Commas concatenate the elements of a vector, so you had 3 elements before, rather than the vector you intended. See the documentation on colon (link) for details.

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Graphics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by