Path: news.mathworks.com!newsfeed-00.mathworks.com!solaris.cc.vt.edu!news.vt.edu!news.glorb.com!postnews.google.com!kr6g2000pbb.googlegroups.com!not-for-mail
From: reza <mjahanbin@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to print Cell with text and numbers?
Date: Mon, 27 Aug 2012 12:11:43 -0700 (PDT)
Organization: http://groups.google.com
Lines: 35
Message-ID: <81b9794b-41ad-4cf6-8a5f-2a2d0e18840c@kr6g2000pbb.googlegroups.com>
References: <k1ga39$m3k$1@newscl01ah.mathworks.com> <3301c796-c0b1-4b3e-8c43-9761d0fa69d9@kr6g2000pbb.googlegroups.com>
NNTP-Posting-Host: 63.107.119.254
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1346095176 24314 127.0.0.1 (27 Aug 2012 19:19:36 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 27 Aug 2012 19:19:36 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: kr6g2000pbb.googlegroups.com; posting-host=63.107.119.254; posting-account=fiGiowoAAABu5GS2SEQGcbwNvSRFssG-
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1,gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:777347

On Aug 27, 3:09pm, reza <mjahan...@gmail.com> wrote:
> On Aug 27, 1:17pm, "Stan " <studentt...@hotmail.com> wrote:
>
> > Hi,
>
> > I need to print an 11 X 24 cell array (named STA). It has text and number in it.
>
> > I am having difficulty with
>
> > >> fprintf(fid1,fmt, STA')
>
> > It gives an error message that it does not recognize a reference to a cell.
>
> > Is there a way to print a cell array in MATLAB, if that array contains text and numbers?
>
> Here is a cheap way that will need improving. It uses ',' as the
> delimiter
>
> joinstr = @(x,y) sprintf(sprintf('%%s%s', y), x{:});
> lines = arrayfun(@(x) joinstr(STA(x,:), ','), 1:size(STA,1),
> 'UniformOutput', false);
> fprintf(fid, '%s', joinstr(lines, '\n'));
>
> note the trailing delimiters at the end of the line. I'll leave it to
> you to write the code to have them removed.
>
> /reza

Alternatively use cellwrite() from MFE,
http://www.mathworks.com/matlabcentral/fileexchange/7363-cellwrite

/reza