cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

What should be the iterator

YA_10963798
14-Alexandrite

What should be the iterator

Hi there ,

I have a nested variable called x =[k v m] as shown in the screen shot

YA_10963798_0-1732636762568.png

I need to divide x by n 

YA_10963798_1-1732636820516.png

YA_10963798_3-1732637094363.png

 

which means that each row in x will be divided by n >>> so k/n , v/n, and m/n>>>> 

the result should look like x

YA_10963798_2-1732637024643.png

Thanks in advance

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:YA_10963798)

In the sheet you posted it was variable "x" which had that nested structure.

Now it seems to be q.c. So you would have to write q.c instead of x in both variants.

The point is that the variable you use at the left hand side of the assignment must already have the nested data structure.

 

You could also turn the calculation into a function, but this probably would not make much sense as you would only use it once.

But here the name of the formal function arguments must not have something to do with the names of the actual arguments you use.

Werner_E_0-1732661969274.png

Nonetheless you should be aware that all these routines are not generic utility routines but only work with the very specific data structure you had provided.

 

View solution in original post

4 REPLIES 4
Werner_E
25-Diamond I
(To:YA_10963798)

So your data, your vector x basically consists of nine 5x1 vectors and you want the elements of each of this nine vectors by the elements of the 5x1 vector n? Is this correct.

Bu the nine 5x1 vectors are arranged in a double nested way in x.

I wonder if this nested data structure really is mandatory for your application.

If its is I would suggest using a small program with nested if-loops instead of fiddling around with range variables.

You should also be aware that 100% = 1, so multiplying by 100% has no effect at all.

But you always can display numeric results formatted in percent if its that what you tried to do

Werner_E_0-1732644939959.png

 

BTW, your attempt with vectorization failed because x[i.n and n are not vectors of the same structure. n is a 5x1 vector consisting of scalars, but x[i.n is a 3x1 vector consisting of 5x1 vectors of scalars.

 

Basically vectorization cycles through the elements of the vectors (just the top level) and applies the calculation to each element. So you can  replace vectorization by an explicit loop. Here a version where the vectorization used above is replaced by an additional for-loop (k):

Werner_E_1-1732645444876.png

Word of caution: Prime would throw an error if you replace the x in x[i[j[k on the left hand side of the assignment by any other variable like R (for Result/Return value) because it can't generate that multiple nested structure in one go.

If you feel uncomfortable with x also use as return value variable you would have to do it that way

Werner_E_2-1732645638062.png

 

 

YA_10963798
14-Alexandrite
(To:Werner_E)

Hi Werner, 

I hope you are doing well. 

1) I wonder if this nested data structure really is mandatory for your application>>> Yes it has to be like this ...

YA_10963798_0-1732647254385.pngYA_10963798_1-1732647264368.png

 

this is the orginal sheet ...I think your caution happens ?

Prime would throw an error if you replace the x in x[i[j[k on the left hand side of the assignment by any other variable like R (for Result/Return value) because it can't generate that multiple nested structure in one go.

 

Werner_E
25-Diamond I
(To:YA_10963798)

In the sheet you posted it was variable "x" which had that nested structure.

Now it seems to be q.c. So you would have to write q.c instead of x in both variants.

The point is that the variable you use at the left hand side of the assignment must already have the nested data structure.

 

You could also turn the calculation into a function, but this probably would not make much sense as you would only use it once.

But here the name of the formal function arguments must not have something to do with the names of the actual arguments you use.

Werner_E_0-1732661969274.png

Nonetheless you should be aware that all these routines are not generic utility routines but only work with the very specific data structure you had provided.

 

YA_10963798
14-Alexandrite
(To:Werner_E)

That works now>>>>>>>>.. Thank youuuuuuuuuuuuuuuuuuuuuuu

Announcements

Top Tags