function csvwrite(filename, m, r, c)
%CSVWRITE Write a comma separated value file.
%   CSVWRITE(FILENAME,M) writes matrix M into FILENAME as 
%   comma separated values.
%
%   CSVWRITE(FILENAME,M,R,C) writes matrix M starting at offset 
%   row R, and column C in the file.  R and C are zero-based,
%   that is R=C=0 specifies first number in the file.
%
%   NOTE: Any elements whose value is 0 will be omitted.  For example,
%   The array [1 0 2] will appear in a file like '1,,2'.
%
%   See also CSVREAD, DLMREAD, DLMWRITE, WK1READ, WK1WRITE.

%   Brian M. Bourgault 10/22/93
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 5.6 $  $Date: 1997/11/21 23:35:04 $

%
% test for proper filename
%
if ~isstr(filename)
    error('FILENAME must be a string.');
end

%
% Call dlmwrite with a comma as the delimiter
%
if nargin < 3
    r = 0;
end
if nargin < 4
    c = 0;
end
dlmwrite(filename, m, ',', r, c);
