function plotfd(celldata, idx)
% PLOTFD - plot fundamental diagram for given freeway cell.
%
% Call: plotfd(celldata, idx)
%
% Parameters:
% celldata - array of freeway cell data structures;
% idx - index to this array, which should positive and
% not exceed the length of 'celldata'.
%
% Returns: none.
%
% Last modified: 07/30/2006.
%
% Alex Kurzhanskiy <akurzhan@eecs.berkeley.edu>
%
N = size(celldata, 2); % number of cells
if (idx < 1) | (idx > N)
error('PLOTFD: index exceeds matrix dimensions.');
end
dc = celldata(idx).FDrhocrit;
dj = celldata(idx).FDrhojam;
fm = celldata(idx).FDfmax;
ih = ishold;
plot([0 dc], [0 fm], 'g', 'LineWidth', 2);
hold on;
plot([dc dj], [fm 0], 'r', 'LineWidth', 2);
plot([dc dj], [fm 0], 'ko');
title(sprintf('FD for cell %d (%d lanes)', idx, celldata(idx).lanes));
xlabel('Density (vpm)');
ylabel('Flow (vph)');
if ih == 0
hold off;
end
return;