Code covered by the BSD License  

Highlights from
CTMSIM - an interactive freeway traffic macrosimulator

image thumbnail
from CTMSIM - an interactive freeway traffic macrosimulator by Alex Kurzhanskiy
Freeway traffic simulation based on Asymmetric Cell Transmission Model

set_or_flows(celldata, flows)
function new_cd = set_or_flows(celldata, flows)
% SET_OR_FLOWS - set on-ramp flow values to the array of freeway 
%                cell data structures from given vector.
%
% Call:   new_cd = set_or_flows(celldata, flows)
%
% Parameters:
%             celldata - array of freeway cell data structures;
%             flows    - vector of on-ramp flows whose size must be the same
%                        as number of cells.
%
% Returns:   new_cd - updated array of freeway cells.
%
% Last modified:   09/26/2007.

%
% Alex Kurzhanskiy   <akurzhan@eecs.berkeley.edu>
%

N = size(celldata, 2);  % number of cells
M = size(flows, 1);

if M ~= N
  error('SET_OR_FLOWS: size of flow vector does not match the number of cells.');
end

new_cd = celldata;

for i = 1:N
  if ~isempty(new_cd(i).ORname) & (flows(i, 1) >= 0)
    new_cd(i).ORflow = flows(i, 1);
  else
    new_cd(i).ORflow = 0;
  end
end

return;

Contact us at files@mathworks.com