Plot, graph a polynomial

25 次查看(过去 30 天)
Joseph
Joseph 2014-11-10
评论: Geoff Hayes 2014-11-10
here is my code. it keeps giving me errors
t = 0:10:1000;
x= {(3*sin(t) + 10*sin(t/10) + 500*sin(2*pi*t/1000))};
plot(x,t)

回答(2 个)

Geoff Hayes
Geoff Hayes 2014-11-10
Joseph - the error is
Error using plot
Conversion to double from cell is not possible.
The resolution is to remove the braces around your initialization of x so that it is not a cell array. Change this line of code to
x = 3*sin(t) + 10*sin(t/10) + 500*sin(2*pi*t/1000);
and re-plot the data.
  2 个评论
Joseph
Joseph 2014-11-10
I did that,and the error message is gone, but nothing is showing up on the graph
Geoff Hayes
Geoff Hayes 2014-11-10
Joseph - something should appear (and it did for me) so please verify that your t and x are populated as expected. Try the following as well
clear all; % clears all local variables
close all; % closes all open figures
t = 0:10:1000;
x= 3*sin(t) + 10*sin(t/10) + 500*sin(2*pi*t/1000);
plot(x,t)
or, as Image Analyst has shown, as
plot(t,x)
so that time is along the horizontal axis.

请先登录,再进行评论。


Image Analyst
Image Analyst 2014-11-10
Joseph, try this:
t = 0:10:1000;
x= 3*sin(t) + 10*sin(t/10) + 500*sin(2*pi*t/1000);
% Now plot
plot(t, x, 'bo-', 'LineWidth', 2);
% Make it fancy.
grid on;
xlabel('t', 'FontSize', 25);
ylabel('x', 'FontSize', 25);
title('x vs. t', 'FontSize', 25);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);

类别

Help CenterFile Exchange 中查找有关 Directed Graphs 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by