matlab代码实例

% 提取运动学片段
a = xlsread('文件1.xlsx',1,'B2:B185726')
area_zero = 1;
begin_array = [];
end_array = [];
cur_index = 1;
begin_array(cur_index) = 1
begin = 1; 
for i = 1:185725
	if area_zero == 1
		if a(i) == 0
			continue;
		else
			area_zero = 0;
		end
	elseif area_zero == 0
		if a(i) == 0
			area_zero = 1;
			end_array(cur_index) = i;
			cur_index = cur_index + 1;
			begin_array(cur_index) = i;
		end
	end
end
% 更新差值
speeds = xlsread('文件1.xlsx',1,'B2:B185726');

speeds = a;
diff = 0;
for i = 2:length(speeds)
	diff = speeds(i) - speeds(i - 1);
	if diff >= 3.968
		diff = 3.96;
	elseif diff <= -8
		diff = -8;
	else
		diff = 0;
	end
	if diff ~= 0
		speeds(i) = speeds(i-1) + diff;
	end
end
%求各运动学片段的平均速度
average_speeds = [];
for i = 1:length(end_array)
	average_speeds(i) = mean(a(begin_array(i):end_array(i)));
end
%求各运动学片段的最大速度
max_speeds = [];
for i = 1:length(end_array)
	max_speeds(i) = max(a(begin_array(i):end_array(i)));
end
%求各运动学片段的运行距离
sum_distances = [];
for i = 1:length(end_array)
	sum_distances(i) = sum(a(begin_array(i):end_array(i)));
end
%求各个运动学片段的加速行驶时间,减速行驶时间,匀速行驶时间
up_speed_time = [];%加速行驶时间
down_speed_time = [];%减速行驶时间
equal_speed_time = [];%匀速行驶时间
for i = 1:length(end_array)
	up_speed_time(i) = 0;
	down_speed_time(i) = 0;
	equal_speed_time(i) = 0;
	for j = (begin_array(i)+1):end_array(i) %j代表各个运动学片段元素的下标
		if a(j) > a(j - 1)
			up_speed_time(i) = up_speed_time(i) + 1;
		elseif a(j) < a(j - 1)
			down_speed_time(i) = down_speed_time(i) + 1;
		elseif a(j) == a(j - 1)
			equal_speed_time(i) = equal_speed_time(i) + 1;
		end
	end
end
%求运动状态下各运动学片段的下标
launch_begin_array = [];%去除怠速时间之后的各运动学片段开始时的下标
launch_end_array = [];%%去除怠速时间之后的各运动学片段结束时的下标
for i = 1:length(end_array)
	for j = begin_array(i):end_array(i)
		if a(j) == 0 %说明是怠速状态
			continue;
		else %运动状态
			launch_begin_array(i) = j;
			launch_end_array(i) = end_array(i);
			break;
		end
	end
end
%求各运动学片段的最大加速度,最小加速度
accelerations = [];%accelerations表示加速度
accelerations(1) = 0;
for i = 2:length(a)
	accelerations(i) = a(i) - a(i - 1);
end
max_acceleration = [];%各运动学片段的最大加速度
min_acceleration = [];%各运动学片段的最小加速度
for i = 1:length(launch_end_array)
	max_acceleration(i) = max(accelerations(launch_begin_array(i):launch_end_array(i)));
	min_acceleration(i) = min(accelerations(launch_begin_array(i):launch_end_array(i)));
end
%求各运动学片段的平均加速度,平均减速度
average_minu_acceleration = [];%各运动学片段的平均减速度
average_acce_acceleration = [];%各运动学片段的平均加速度
for i = 1:length(end_array)
	minu_time = 0;%该运动学片段减速运行的总时间
	acce_time = 0;%该运动学片段加速运行的总时间
	minu_acceleration_total = 0;%该运动学片段的减速度总和
	acce_acceleration_total = 0;%该运动学片段的加速度总和
	for j = launch_begin_array(i):launch_end_array(i)
		if accelerations(j) > 0 %加速度大于0
			acce_acceleration_total = acce_acceleration_total + acceleration(j);
			acce_time = acce_time + 1;
		elseif accelerations(j) < 0 %加速度小于0
			minu_acceleration_total = minu_acceleration_total + acceleration(j);
			minu_time = minu_time + 1;
		end
	end
	average_minu_acceleration(i) = minu_acceleration_total / minu_time;
	average_acce_acceleration(i) = acce_acceleration_total / acce_time;
end
%求各运动学片段的平均行驶速度
average_launch_speed = [];
for i = 1:length(end_array)
	average_launch_speed(i) = sum(a(launch_begin_array(i):launch_end_array(i))) / (launch_end_array(i) - launch_begin_array(i) + 1);
end
%求各运动学片段的最大速度
max_speeds = [];
for i = 1:length(end_array)
	max_speeds(i) = max(a(begin_array(i):end_array(i)));
end
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值