Path: news.mathworks.com!not-for-mail
From: "Jos " <DELjos@jasenDEL.nl>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Printing a cell array
Date: Fri, 16 May 2008 09:47:10 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 41
Message-ID: <g0jl6u$2n1$1@fred.mathworks.com>
References: <b44e861c-f621-4d52-a70b-b433f7420339@x35g2000hsb.googlegroups.com>  <c796a606-58d8-4874-b4cc-d5c6d8602495@c65g2000hsa.googlegroups.com>
Reply-To: "Jos " <DELjos@jasenDEL.nl>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210931230 2785 172.30.248.37 (16 May 2008 09:47:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 16 May 2008 09:47:10 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:468789


n o s p a m p l e a s e <nospam.please@alum.com> wrote in
message
<c796a606-58d8-4874-b4cc-d5c6d8602495@c65g2000hsa.googlegroups.com>...
> On May 13, 12:16=A0am, Bob <rbe...@mathworks.com> wrote:
> > Does this help?
> >
> > for k=3D1:nb
> > =A0 =A0fprintf('%d =A0 =A0%s\n',k,Names{k})
> > end
> >
> > Cheers
> > Bob
> 
> Yes it works but I want it in vector form i.e. something
as follows:
> 
> fprintf('%d    %s\n',[1:nb],Names{[1:nb]})
> 
> and the above doesn't work. Any guess how I can put it in
vector form.
> 
> Thanx/NSP

An example of comma-separated list expansion:

x = 1:3 ;
t = {'AA','B','CCC'} ;

% one big cell array
M = [num2cell(x) ; t] 

% expansion
fprintf('\n%d\t %s',M{:})

Note that the order of M is important, before you apply
comma-separated list expansion. You might have to transpose
M before.

hth
Jos