Path: news.mathworks.com!newsfeed-00.mathworks.com!panix!newsfeed.stanford.edu!postnews.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe01.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Write date in excel
References: <a3aebc93-c3b0-408a-9533-b11361f006ac@r15g2000prh.googlegroups.com>
In-Reply-To: <a3aebc93-c3b0-408a-9533-b11361f006ac@r15g2000prh.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 38
Message-ID: <R96Qk.21254$7o4.19758@newsfe01.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe01.iad 1225846513 24.79.146.116 (Wed, 05 Nov 2008 00:55:13 UTC)
NNTP-Posting-Date: Wed, 05 Nov 2008 00:55:13 UTC
Date: Tue, 04 Nov 2008 18:55:34 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:498974


Rosy wrote:

> Date = datestr(A);
> xlswrite(xlsfilename, Date);

If you are communicating with a "real" Excel (via a COM service on MS Windows) then
there might be a way such as (guessing here)

xlswrite(xlsfilename, cellstr(Date));

If, however, you are on any of the other operating systems or you (for whatever reason)
cannot get a COM session established to Excel (e.g., if you don't actually have Excel
installed and are just wanting the file format), then xlswrite is only able to write in
comma separated value format (CSV), not true Excel files. And if you are in that
situation, then you have to deal with the fact that xlswrite will treate each individual
character as being a separate array value (which is how characters are stored in Matlab)
and will write them out one per cell, with the delimeter in between. In order to avoid
that happening, you have to use dlmwrite() instead and tell it that the cell delimiter
is '' (the empty string): that will cause dlmwrite to put each row of text into a cell
(one per line). But if you are doing that, then you have a bit of a mess if you are trying
to combine text and numeric data in the output; the only way to get around that is to
convert -everything- to text ahead of time (e.g., using sprintf() or num2str())
and write it all out using dlmwrite() with the delimiter set to '' (the empty string),
and in this situation you have to "manually" put in the commas where you want them.

For example,

dlmwrite(xlsfilename, ...
  [char(Date), repmat(',', size(Date,1), 1), num2str(SomeRowVector .')], ...
  'Delimiter', '');

just to get the date followed by a comma followed by a number, one per line.

-- 
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?