This is about the content of the Forums Anyscript.org
The old thread title is “vector assignment question” by shashu_23. (2008.03.04)
Sylvain responsed:
You can also define a general rule that you can use for different
situations by just changing the first element i and choosing the n
number you want (in this case n will be 25) :
AnyInt i = 49;
AnyVector a = {b[i], b[i+1], b[i+2], [COLOR=red]“…until…” b[i+n]};[/COLOR]
The red part seems to become random code!
What does it mean?
Could you help me to get that red part?
Thanks a lot.
that was a pseudo code with some text elements. The intention was to say:
{b[i], b[i+1], b[i+2], …, b[i+n]};
Since that time the modelling system has developed and you may solve your problem in a different manner. For example, one can use iarr function.
If you still haven’t found an answer to your question here - let us know.
As the following example:
Data = AllData(600:1800)
I need 600th to 1800th elements of vector AllData to calculate its mean.
The way I thought is:
AnyInt i = 600;//starting index
AnyInt j = 1800;//ending index
AnyInt k = NumElemOf(AllData);//number of elements
AnyVector a = iarr(1,i)*0;//creat a zero-vector
AnyVector b = pow(iarr(1,j-i+1),0);//creat an one-vector
AnyVector c = iarr(1,k-j-1)*0;//creat a zero-vector
AnyVector d = arrcat(a, arrcat(b, c));//combine in order, as long as AllData
AnyFloat Data_mean = (d*AllData')/(j-i+1);
Is there a better or simple way to do the same job?
No, I can’t think of a more elegant way. This is probably the only way right now with a minor improvement:
“AnyVector b = iarr(1,j-i+1)*0+1; //create ones”
Actually there is another solution that I could think of. Came a bit late
You could use your own functions written in C or Python within AnyScript. Needed function in Python would look very easy and elegant.
Please search for AnyFunEx in the script reference manual. There is an example how that can be done.