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_densities(den, fn)
function set_densities(den, fn)
%
% SET_DENSITIES - set initial densities in the ctmsim configuration file.
%
% Call:
%       set_densities(den)
%       set_densities(den, fn)
%
% Parameters:
%             den - vector of initial densities whose size must equal the number
%                   of cells in the configured freeway;
%             fn  - (optional) name of the configuration file, default is 'ctm.mat'.
%
% Returns:   none.
%
% Last modified:   08/30/2006.

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

if nargin < 2
  fn = 'ctm';
end

load(fn);

if ~isstruct(celldata)
  error('SET_DENSITIES: invalid configuration file.');
end

N = size(celldata, 2);
M = size(den, 1);

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

configFile       = fn;
initialDensities = den(:, 1);

clear N M fn den;

if str2num(version('-release')) >= 14
  feval(@save, '-v6', configFile);
else
  feval(@save, configFile);
end

return;

Contact us at files@mathworks.com