Matrix dimensions must agree.

20 ビュー (過去 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 Center および File ExchangeFrequency Transformations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by