How to calculate distance till the next possible stop?
1 view (last 30 days)
Show older comments
Asrorkhuja Ortikov
on 6 Jul 2020
Commented: Asrorkhuja Ortikov
on 6 Jul 2020
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 Comments
Accepted Answer
Rafael Hernandez-Walls
on 6 Jul 2020
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)
More Answers (0)
See Also
Categories
Find more on MATLAB Support Package for Parrot Drones in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!