[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: An array of arrays?
From: |
Henry F. Mollet |
Subject: |
Re: An array of arrays? |
Date: |
Wed, 03 Nov 2004 09:51:18 -0800 |
User-agent: |
Microsoft-Entourage/10.1.1.2418 |
I've tried "a={a{1:2},b,a{3}};" but b replaced element 3. I also tried
"a={a{1:3},b};" and element 3 was deleted.
Henry
octave:18> a{1} = 1;
octave:19> a{2} = [1,1,1];
octave:20> a{3} = "string";
octave:21> a
a =
{
[1,1] = 1
[1,2] =
1 1 1
[1,3] = string
}
octave:23> b="NewString"
b = NewString
octave:24> a={a{1:2},b,a{3}};
octave:25> a
a =
{
[1,1] = 1
[1,2] =
1 1 1
[1,3] = NewString
}
********
octave:36> a{1} = 1;
octave:37> a{2} = [1,1,1];
octave:38> a{3} = "string";
octave:39> a
a =
{
[1,1] = 1
[1,2] =
1 1 1
[1,3] = string
}
octave:40> whos
*** local user variables:
prot type rows cols name
==== ==== ==== ==== ====
rwd cell 1 3 a
rwd string 1 9 b
octave:41> b
b = NewString
octave:42> a={a{1:3},b}
a =
{
[1,1] = 1
[1,2] =
1 1 1
}
octave:43> whos
*** local user variables:
prot type rows cols name
==== ==== ==== ==== ====
rwd cell 1 2 a
rwd string 1 9 b
********
on 11/2/04 7:38 PM, Quentin Spencer at address@hidden wrote:
> In order to insert a variable b between elements 2 and 3 you could use
> the following command:
>
> a={a{1:2},b,a{3}};
>
>
>
> Henry F. Mollet wrote:
>
>> I'm beginning to understand what a cell array is about. Assume that I
>> constructed a large cell array and that I forgot one item. How do I squeeze
>> in an additional item at a specified location, say between a{2} and a{3} in
>> the example below without starting from scratch and a{3} will become a{4}?
>>
>> Also, if
>> octave:42> a{3}
>> ans = string
>> Why is
>> octave:41> a{[3,1]}
>> ans =
>> (
>> [1] = string
>> [2] = 1
>> )
>>
>> Henry
>>
>>
>>
>> on 11/1/04 6:23 AM, Quentin Spencer at address@hidden wrote:
>>
>>
>>
>>> I think a cell array is what you're looking for. Each element of a cell
>>> array can have a different type and different dimensions. Cell arrays
>>> are indexed using {}. For example:
>>>
>>> octave:1> a{1} = 1;
>>> octave:2> a{2} = [1,1,1];
>>> octave:3> a{3} = "string";
>>> octave:4> a
>>> a =
>>>
>>> {
>>> [1,1] = 1
>>> [1,2] =
>>>
>>> 1 1 1
>>>
>>> [1,3] = string
>>> }
>>>
>>> I hope this helps.
>>>
>>> Quentin
>>>
>>>
>>>
>>> Vic Norton wrote:
>>>
>>>
>>>
>>>> Here is my problem. I have a subroutine
>>>> [X, S] = solsp(rtns, rtn0, noshort)
>>>> that produce a k x n matrix, X, and a k x 1 matrix, S, from a given m
>>>> x n matrix, rtns, an m x 1 matrix rtn0, and a (possibly empty)
>>>> submatrix, noshort, of [1 : n]. The integers m and n are fixed, but k,
>>>> the number of rows of X and S, varies, depending on the data matrices
>>>> rtns and rtn0.
>>>>
>>>> The matrices rtns and rtn0 are actually samples of historical returns
>>>> on certain investments ending at a certain week. I would like to run
>>>> through a bunch of end-weeks (wk = 1, 2, ..., N) and collect and save
>>>> the corresponding [X, S] output. The natural data structure would be a
>>>> list [X(wk), S(wk)] (wk = 1, 2, ..., N) of pairs of arrays of varying
>>>> row dimensions, k(wk) (wk = 1, 2, ..., N). Is there any reasonably
>>>> efficient way to create and save such a data structure in Octave?
>>>>
>>>> Note, all arrays contain floating point numbers except for the fixed
>>>> integer array noshort.
>>>>
>>>> Any ideas would be greatly appreciated.
>>>>
>>>> Regards,
>>>>
>>>> Vic Norton
>>>>
>>>>
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web: http://www.octave.org
> How to fund new projects: http://www.octave.org/funding.html
> Subscription information: http://www.octave.org/archive.html
> -------------------------------------------------------------
>
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------