Matrix dimensions must agree.

조회 수: 21 (최근 30일)
Luyen Tran
Luyen Tran 2020년 12월 23일
답변: Image Analyst 2020년 12월 23일
Where is problem? please helpp me ;(((
function ptcd_ptqd
clc
clear var1
clear var2
close all
%% NHAP DU LIEU
t = linspace(0,5,6);
%% TINH TOAN TOA DO
x = 3*t.^2-(4/3*t.^3) ; % hoanh do [m]
y = 8*t ; % tung do [m]
dt = diff(t);
dx = diff(x);
dy = diff(y);
%% TINH TOAN VAN TOC
vx = dx./dt ; % thanh phan van toc theo phuong ngang [m/s]
vy = dy./dt ; % thanh phan van toc theo phuong thang dung [m/s]
v = sqrt(vx.^2+vy.^2); % van toc
dt = diff(t);
dvx = diff(vx);
dvy = diff(vy);
%% TINH TOAN GIA TOC
ax = dvx./dt; % thanh phan gia toc theo phuong ngang [m/s^2]
ay = dvy./dt ; % thanh phan gia toc theo phuong thang dung [m/s^2]
a = sqrt(ax.^2+ay.^2); % gia toc
%% FIGURE
figure('name','Toa do','color','white','numbertitle','off');
plot(t,x,'linewidth',2);
xlabel('Thoi gian');
ylabel('Toa do [m]');
figure('name','Van toc','color','white','numbertitle','off');
plot(tv,v,'linewidth',2);
xlabel('Thoi gian');
ylabel('Van toc [m/s]');
figure('name','Gia toc','color','white','numbertitle','off');
plot(ta,a,'linewidth',2);
xlabel('Thoi gian');
ylabel('Gia toc [m/s^2]');
end

답변 (1개)

Image Analyst
Image Analyst 2020년 12월 23일
dt does not have one element for every element. It has one element for every PAIR of elements. Since all your dt are the same, just do this
dt = t(2) - t(1);
to get the difference between any two t elements (since the spacing is uniform).

카테고리

Help CenterFile Exchange에서 Frequency Transformations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by