[scilab-Users] Using a cell entry to access part of a matrix

Iai Masafumi ax iai at axelspace.com
Mon Nov 7 23:52:33 CET 2011


Thank you, Adrien. You are exactly right. I was trying to do what I used
to do with Matlab. The code you gave me helps a lot!

Iai



(2011/11/08 7:43), Adrien Vogt-Schilb wrote:
> Iai,
> 
> y(cell2mat(II(1)))
> 
> should be what you are looking for
> (in the previous mail m was unnecessary)
> 
> On 07/11/2011 23:31, Adrien Vogt-Schilb wrote:
>> On 07/11/2011 23:19, Iai Masafumi ax wrote:
>>> Thanks for your reply. I wanted to use a cell array to manage a lot of
>>> variable in my code which is more complicated.
>>>
>>> I guess I have to put my question in a different way:
>>>
>>> After running the code below, type(II(1)) returns 17 while type(ii)
>>> returns 1. According to the help, 1 means "real or complex constant
>>> matrix". 17 means "matrix oriented typed list (mlist)". How do I convert
>>> II(1) into a "real or complex constant matrix"?
>>>
>> hi
>>
>> you could use :
>>
>> m=cell2mat(II) //converts cell to matrix, what you asked.
>> m(1,:)
>>
>>
>>
>> if you build yourself the cell, i am guessing you are trying to mimic 
>> something you are used to do with matlab
>> in that case, consider:
>>
>> 1-using structures instead of cells
>> y=[100:110]
>> ii=[1 3 5 7];
>> jj=[2 4 6 8];
>> y(ii)   // OK. This is an ordinary way.
>>
>> //build
>> II.actual_name_i=ii;
>> II.myindexes=jj;
>> //access
>> y(II("myindexes "))
>> y(II.actual_name_i )
>>
>> //useful for loops
>> fieldnames(II)
>>
>> 2-using hypermatrices if ii and jj will always have the same size
>> II = zeros(1,4,2)
>> II(:,:,1) = ii;
>> II(:,:,2) = jj;
>>
>> y(II(:,:,1))
>>
>>
>> hope this helps
>>
>> -- 
>> Adrien Vogt-Schilb (Cired)
>> Tel: (+33) 1 43 94 *73 77*
> 
> 
> -- 
> Adrien Vogt-Schilb (Cired)
> Tel: (+33) 1 43 94 *73 77*



More information about the users mailing list