cs-list general question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

cs-list general question

JokerOne
Hi all, and sorry, this question has probably posted 100 times but I cannot find anything proper by searching:

Say:
a(1).b(1).c = 1;
a(2).b(1).c = 2;
a(1).b(2).c = -1;

How do I get [1,2] in a vector from this structure?
i.e. something like:
result = a(:).b(1).c  

but this does not work? (error a cs-list cannot be....)

A loop will do, of course, but I am pretty sure, that you can do it in one line?
JokerOne
Reply | Threaded
Open this post in threaded view
|

Re: cs-list general question

c.-2

On 28 Aug 2014, at 18:08, JokerOne <[hidden email]> wrote:

> How do I get [1,2] in a vector from this structure?
> i.e. something like:
> result = a(:).b(1).c

does this work?

result = [a(:).b(1).c]

c.
_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: cs-list general question

JokerOne
Thanks for the answer, c, but unfortunately this does not work:

>>> a(1).b(1).c = 1;
>>> a(2).b(1).c = 2;
>>> a(1).b(2).c = -1;
>>> [a(:).b(1).c]
>>>error: a cs-list cannot be further indexed
Reply | Threaded
Open this post in threaded view
|

Re: cs-list general question

bpabbott
Administrator
On Aug 31, 2014, at 8:07 AM, JokerOne <[hidden email]> wrote:

> Thanks for the answer, c, but unfortunately this does not work:
>
>>>> a(1).b(1).c = 1;
>>>> a(2).b(1).c = 2;
>>>> a(1).b(2).c = -1;
>>>> [a(:).b(1).c]
>>>> error: a cs-list cannot be further indexed

You can get close to what you want by indexing ...

        [[a.b].c]

... which returns [[a(1).b(1).c, a(2).b(1).c], a(1).b(2).c]

To limit the result to a(1:end).b(1).c ...

        [[a.b].c](1:numel(a))

Ben


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: cs-list general question

JokerOne
Thanks Ben,

but still not exactly this, what I want:

>>> [[a.b].c](1:numel(a))
ans =

   1  -1

But I want 1 2.

In addition, I would prefer a more general solution, which does not require me to count the entries, like:

wanted_results =  [[a.b].c]([1,3])

Is there anything that does the trick?

Also, what happens, when I 'd like the -1, eg. [[a.b].c]([2]), or if I start to play with:
a(1).b(1).c(1).d = 1
etc....