[scilab-Users] can index starts from zero

Calixte Denizet calixte at contrib.scilab.org
Mon Oct 25 12:27:36 CEST 2010


Le lundi 25 octobre 2010 à 12:08 +0200, Samuel GOUGEON a écrit :
> ----- Message d'origine -----
> De : Manjusha Joshi
> Date : 25/10/2010 11:57:
> > Hello,

Hello,

> >
> > If I define V=[ 2, 3,4]
> > V(1)=2
> > Can I set index such that V(0)=2
> AFAIK, it is not possible. You have to shift all the indices by 1 in your formula.
> 

There is a workaround: you can wrap your array in a mlist:

a=[4 3 2 1];
A=mlist(['Carray' 'array'],a);
// overload extraction
deff('y=%Carray_e(i,x)','y=x.array(i+1)');
// overload insertion
deff('z=%s_i_Carray(i,x,y)','y.array(i+1)=x;z=y;');
// overload print
deff('%Carray_p(x)','disp(x.array)');

A(0) returns 4 and A(0)=5 inserts 5 at the first place. Have a look at
the help page about overloading and mlist.

Best regards

Calixte

> The syntax L(0)=value is only possible in lists L, to insert a new component at
> the beginning of the list. But then, the index of the inserted value is 
> automatically
> reset to 1 while the ones of other components are also incremented.
> 
> I am afraid that you have to cope with this technical design...
> 
> Regards
> Samuel
> 





More information about the users mailing list