Vectors must be the same length.

조회 수: 15 (최근 30일)
Ameyr Rosha
Ameyr Rosha 2021년 5월 30일
답변: Star Strider 2021년 5월 30일
Help!!! im trying to plot a graph. But its always tell me 'Vectors must be the same length.'
h=0.04; %step size
t=0.04:h:0.6; %time
y=[0.1560 0.0125 0.0850 0.2360 0.2450 0.0350 0.5610];%Displacement
v=diff(y)/h; %First derivative of y
a=diff(v)/h; %Second derivative of y
j=diff(a)/h; % Third derivative of y
%plot y vs t
plot(t,y,'LineWidth',2);
grid on
xlim([min(t) max(t)])
xlabel('t')
ylabel('y')
title('Plot of y vs. t')
Error using plot
Vectors must be the same length.
  댓글 수: 1
Torsten
Torsten 2021년 5월 30일
What is the t vector that corresponds to the displacement vector ? It must have 7 elements.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 5월 30일
Use the gradient function instead of diff and define ‘t’ based on ‘y’
% h=0.04; %step size
% t=0.04:h:0.6; %time
y=[0.1560 0.0125 0.0850 0.2360 0.2450 0.0350 0.5610];%Displacement
t = linspace(0.04, 0.6, numel(y));
h = t(2)-t(1)
h = 0.0933
v=gradient(y,h); %First derivative of y
a=gradient(v,h); %Second derivative of y
j=gradient(a,h); % Third derivative of y
%plot y vs t
figure
plot(t,y,'LineWidth',2);
grid on
xlim([min(t) max(t)])
xlabel('t')
ylabel('y')
title('Plot of y vs. t')
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by