Path: news.mathworks.com!not-for-mail
From: "Sadik " <sadik.hava@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: character array from cell
Date: Fri, 3 Jul 2009 21:56:12 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 44
Message-ID: <h2lups$6pn$1@fred.mathworks.com>
References: <h2lqkf$cqp$1@fred.mathworks.com> <h2lt51$m7h$1@fred.mathworks.com> <h2ltg9$ekf$1@fred.mathworks.com>
Reply-To: "Sadik " <sadik.hava@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246658172 6967 172.30.248.35 (3 Jul 2009 21:56:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 3 Jul 2009 21:56:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1666517
Xref: news.mathworks.com comp.soft-sys.matlab:552735


Hi,

You can loop through f like this.

% First determine the longest sequence
maxLength = 0;
for k = 1:length(f)
    currentSeqLength = length(char(f{k}));
    if currentSeqLength > maxLength
        maxLength = currentSeqLength;
    end
end

% Now that we know the maximum length, we can now loop through f and get 
% the character array, say charF.

for k = 1:length(f)
    currentSeq = char(f{k});
    charF(k,:) = [currentSeq repmat(' ',1,maxLength-length(currentSeq))];
end

This should now work as you wanted.

Best.

<h2ltg9$ekf$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <h2lt51$m7h$1@fred.mathworks.com>...
<h2lqkf$cqp$1@fred.mathworks.com>...
> > > Is there any way I can make a 2*1 character array from a 2*1 cell? I have a 2*1 cell:
> > > f{1}=x+y+1 and f{2}=3x-5y+10, (x and y are syms) I want to have a char G<2*1> with exactly the same elements. 
> > > 
> > > ps. the Matlab version I'm using is not very updated, so I'm looking for a way using basic commands in matlab not by specific toolboxes.  any suggestions?
> > > 
> > > Thank you
> > 
> > you've been given solutions to your problem earlier...
> > tell CSSM what ML version you have...
> > 
> > us
> 
> The solutions did not work, so I'm asking for an alternative.
> the version I have is 7.0.4.
> 
> mohammad