Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Basic Matlab Question
Date: Tue, 17 Nov 2009 09:46:47 -0500
Organization: The MathWorks, Inc.
Lines: 53
Message-ID: <hducuk$r51$1@fred.mathworks.com>
References: <hdso7p$sh5$1@fred.mathworks.com> <hdsqh1$flv$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1258469140 27809 172.31.44.65 (17 Nov 2009 14:45:40 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Nov 2009 14:45:40 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
X-RFC2646: Format=Flowed; Original
Xref: news.mathworks.com comp.soft-sys.matlab:585780



"Doug " <nospam@thx.com> wrote in message 
news:hdsqh1$flv$1@fred.mathworks.com...
> "James Carter" <jimctr@msn.com> wrote in message 
> <hdso7p$sh5$1@fred.mathworks.com>...
>> I have a 32 x 1300 2D array, lets call it S.  I know I can pick off a 
>> particular row with the following argument: A = S(1,:); which gives me a 
>> 1 x 1300 array from the first
>> row of the 2D array.  I want every row assigned to a new indexed array, 
>> so I would start off with
>>
>> for n = 1:rows
>> A(n) = S(n,:);
>> end
>>
>> This doesn't work because of a dimensional mismatch.   I'm not really 
>> trying to define
>> a dimension but simply declare a unique identifier.   How am I able to 
>> assign rows
>> such that I can put them in A(1), A(2), etc., all with the dimension 1 x 
>> 1300.
>>
>> Thanks!
>
> By definition A will be multidimensional since you have A(x) and each A(x) 
> has a length of 1300.
>
> If you need 1 x 1300 vectors you could use a unique name, i.e. A1=..., 
> A2=...

*snip*

NO.  Do NOT use EVAL like this.  See Q4.6 in the newsgroup FAQ for an 
explanation why this is a Bad Idea.

> or maybe use a cell array where each cell contains a 1x1300 array
>
> c=cell(32,1);
> for n = 1:rows
>  c{n}=S(n,:);
> end

To the OP:  I would instead just use S(n, :) wherever in your code you would 
have used A1, A2, ... or A(1), A(2), ...  IMO it's no more difficult to read 
than A1, A2, A(1), A(2), etc. and it avoids creating lots of smaller 
variables in your workspace.

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ