1

I know my question is probably very basic but I have been blocked for 2 days on this... I need to compute a waiting time distribution for passengers in Matlab, like this one. I have the following data:

  1. WT, a vector of waiting times of length L
  2. PAX, a vector of the passengers who experienced waiting time, of length L also. PAX(i) experienced waiting time WT(i), e.g. 3 passengers experienced 1.2 minutes. Passengers are uniformly distributed.

Manually I see how to do it (create bins for WT, to group similar waiting times, and deduce the probability of a passenger having to wait for this specific waiting time) but when I try in Matlab I am blocked. Edit: should I use histcounts?

Thanks a lot,

Anne

Anita
  • 13
  • 3

2 Answers2

1

What about something like:

histogram(repelem(WT,PAX)); 

Explanation:

repelem(WT,PAX) %make a vector where each element WT(i) appears PAX(i) times
histogram(repelem(WT,PAX)) %plot this vector as a histogram

Example:

WT =  [1, 1.4, 13, 6];
PAX = [3, 2, 1, 2];
repelem(WT,PAX) = [1, 1, 1, 1.4, 1.4, 13, 6, 6];
%Can't plot this histogram right now as I don't have a license at this machine, but I will edit one in later.
Ian Riley
  • 523
  • 2
  • 8
0

Another option:

R = normrnd(10,3,100,1); %data sample (= PAX in your case)

%calculate the mu and sigma
mu = mean(R);     
sigma = std(R);

%creation of the model (assuming that you have normally distributed data)

x = mu-5*sigma:0.1:mu+5*sigma 
y = (1/(sigma*sqrt(2*pi)))*exp((-(x-mu).^2/(2*sigma^2))) %the normal distribution formula

%plot the model
plot(x,y)
obchardon
  • 10,614
  • 1
  • 17
  • 33