How to calculate distance till the next possible stop?
1 次查看(过去 30 天)
显示 更早的评论
Is there any formula or ways to calculate distance between current parking place and next possible parking with given data of all durations during the day of a car? let's say on one column I have parking locations, and the other driving distances between stops, but parking is only possible at Home or Workplace, not shopping mall or restaurant.
parkinglocations = ["Home" "mobile" "ShoppingMall" "mobile" "Workplace" "mobile" "Home"]'; % when "mobile" car is driving
driving_distance = [0 35 0 15 0 40 0]';
with these data I want to generate range of a car till next stop where parking is possible, and result should be
next_range = [50 0 0 0 40 0]';
I have tried with cumsum and sum functions like below, but seems like not working. And I don't know how to use complex functions yet, can anybody help please?
next_range = zeros(size(parkinglocations,1),1);
parking_binary = zeros(size(parkinglocations,1),1);
for i=1:length(parkinglocations)
if parkinglocations(i) == "Home" || parkinglocations(i) == "Workplace"
parking_binary(i) = 1;
else
parking_binary(i) = 0;
end
next_range = cumsum(distance(parking_binary==0));
end
0 个评论
采纳的回答
Rafael Hernandez-Walls
2020-7-6
I don't know is correct,
parkinglocations = ["Home" "mobile" "ShoppingMall" "mobile" "Workplace" "mobile" "Home"]'; % when "mobile" car is driving
driving_distance = [0 35 0 15 0 40 0]';
next_range = zeros(size(parkinglocations));
parking_binary = zeros(size(parkinglocations));
for i=1:length(parkinglocations)
if parkinglocations(i) == "Home" || parkinglocations(i) == "Workplace"
parking_binary(i) = 1;
else
parking_binary(i) = 0;
end
end
% New section
n=find(parking_binary==1)';
n(end+1)=n(end);
s=[];r=1;
for k=1:length(n)-1
s=[s,sum(driving_distance(n(k):n(k+1)-1))];
end
sol=parking_binary';
sol(logical(parking_binary))=s;
sol=sol(1:end-1)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for Parrot Drones 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!