[scilab-Users] Using a cell entry to access part of a matrix
Adrien Vogt-Schilb
vogt at centre-cired.fr
Mon Nov 7 23:31:55 CET 2011
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*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20111107/607d3fef/attachment.htm>
More information about the users
mailing list