Plot Error (2-D Graph)
1 次查看(过去 30 天)
显示 更早的评论
So I have a piece of code attached below, when running the code I get an error at the line
plot(c_t1(1:59),c_acc);
so I'm unsure as to why there is an error. Additionally, the circular velocity graphs are screwed up too. (A figure pops up but not lines to indicate the actual thing that is being graphed).
Would it be that my for loop is incorrect?
%circular position intizalization
c_t = linspace(0,2*pi,61);
c_x = 1.2*cos(c_t);
c_y = 1.2*sin(c_t) + 1.2;
%circular position graph
figure;
plot(c_x,c_y)
title('circular x vs. y-position'); xlabel('circular x-position(m)');
ylabel('circular y-position(m)');
grid on; hold on;
c_t1 = linspace(0,60,61);
%loop for circular velocity
for i = 1:(length(c_t1) - 1)
c_vel_x(i) = ((c_x(i+1) - c_x(i)));
c_vel_y(i) = ((c_y(i+1) - c_y(i)));
c_vel = sqrt(c_vel_x(i)^2 + c_vel_y(i)^2);
end
%loop for circular acceleration
for i = 1:(length(c_vel) - 1)
c_acc_x(i) = ((c_vel_x(i+1) - c_vel_x(i)));
c_acc_y(i) = ((c_vel_y(i+1) - c_vel_y(i)));
c_acc= sqrt(c_acc_x(i)^2 + c_acc_y(i)^2);
end
%circular velocity graphs
figure;
plot(c_t1(1:length(c_vel)),c_vel);hold on;
plot(c_t1(1:length(c_vel)),c_vel_x); plot(c_t1(1:length(c_vel)),c_vel_y);
title("circ. velocity vs. time"); xlabel('time(s)');
ylabel('velocity(m/s)');
legend('velocity','x-velocity','y-velocity');
grid on;
%circular acceleration graphs
figure;
plot(c_t1(1:59),c_acc) %this where the error occurs
hold on;
plot(c_t1(1:59),c_acc_x);plot(c_t1(1:59),c_acc_y);
title("circ. acc, vs. time"); xlabel('time(s)'); ylabel('acc.(m^2/s)');
legend('acc.','x-acc','y-acc');
grid on;
0 个评论
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!