?? dis_to_time.m
字號:
function dis_to_time()
INFI=900000000;
% V_max=input('Please enter the max speed in unit of mm/sec)');
% t_max=input('Please enter the max acceleration time(in unit of msec)');
V_max=250;
t_max=600;
%V_max=250; %單位:mm/s
%orgin=[0,0];
%構(gòu)造距離矩陣
data = xlsread('D:\MATLAB701\work\SRT\加速曲線矩陣','sheet2');
m=length(data);
% data(m+1,1)=0;data(m+1,2)=0;
for i=1:m
for j=1:i
distance(i,j) = sqrt((data(i,1)-data(j,1))^2+(data(i,2)-data(j,2))^2);
end
end
%每隔step個(gè)數(shù)據(jù)選擇一個(gè)加速點(diǎn)
num_of_points=t_max/10;
step=240/num_of_points; %單位:msec
%從excel中取出原始加速曲線數(shù)據(jù),將之存放到數(shù)組OR中。根據(jù)step在從OR中取出要用的數(shù)據(jù),存放到數(shù)組B中
i=round(step/2); %從step/2個(gè)點(diǎn)開始取點(diǎn)
j=1;
OR=xlsread('D:\MATLAB701\work\SRT\加速曲線矩陣','sheet1');
while(i<=240)
B(j)=OR(i);
i=i+step;
j=j+1;
end
% orig=[0 cumsum(OR)*V_max/sum(OR)];
%計(jì)算每個(gè)加速點(diǎn)對應(yīng)的速度值,存放到數(shù)組V中
B=cumsum(B);
V=B*V_max/B(num_of_points)/1000; % 單位:mm/msec
t=[10:10:t_max];
% plot(t,V);
%通過數(shù)值積分得每個(gè)加速點(diǎn)對應(yīng)的路程,存放到數(shù)組S中
S(1)=0;T(1)=0;
S(2)=V(1)*10*0.5;
T(2)=10;
for i=3:num_of_points+1
S(i)=10*(V(i-1)+V(i-2))/2;
T(i)=(i-1)*10;
end
S=cumsum(S);
S_max=S(num_of_points+1);
% VV=[0 V];
% pic=[VV;S];
% [AX,H1,H2]=plotyy(T,VV,T,S);
% set(get(AX(1),'Ylabel'),'String','V/mm per msec');
% set(get(AX(2),'Ylabel'),'String','S/mm');
% xlabel('T/msec');
% title('V-T & S-T');
% set(H1,'Marker','+');
% set(H2,'Marker','p');
%---------------------------------------------------
% S_test_1=[0:3:198];
% time_test_1=2*interp1(S,T,S_test_1/2);
% S_test_2=[199:3:250];
% time_test_2=2*t_max+(S_test_2-2*S_max)/V_max*1000;
% S_test=[S_test_1 S_test_2];
% time_test=[time_test_1 time_test_2];
% plot(S_test,time_test,'Marker','*');
%根據(jù)所得出的距離與時(shí)間的對應(yīng)關(guān)系,由坐標(biāo)點(diǎn)之間的距離矩陣distance得到坐標(biāo)點(diǎn)之間的時(shí)間矩陣time (單位 msec)
for i=1:m
for j=1:i
if distance(i,j)>=S_max*2
time(i,j)=2*t_max+(distance(i,j)-2*S_max)/V_max*1000;
else
time(i,j)=2*interp1(S,T,distance(i,j)/2);
end
end
end
n=length(distance);
for i=1:n
distance(i,i)=INFI;
time(i,i)=INFI;
for j=i+1:n
distance(i,j)=distance(j,i);
time(i,j)=time(j,i);
end
end
xlswrite('distance_and_time',n,'n');
xlswrite('distance_and_time',distance,'distance');
xlswrite('distance_and_time',time,'time');
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -