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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

5-Regular Member

## The array order reassign

Hi Masters

How to reassign the array elements order??

tks

1 ACCEPTED SOLUTION

Accepted Solutions
20-Turquoise
(To:lvl107)

Best Regards.

8 REPLIES 8
24-Ruby V
(To:KC_10577235)

Use C:=stack(A,B)

Ooops, I should have used my glasses, indeed!
Sorry! See the reply of @lvl107  for a correct solution.

20-Turquoise
(To:KC_10577235)

It seems like this :

Best Regards.

Loi.

20-Turquoise
(To:lvl107)

Best Regards.

24-Ruby V
(To:lvl107)

I guess this is just my second appraoch with differently named variables and without being ORIGIN-independent and without error checking, right? 😉

5-Regular Member
(To:lvl107)

Hi Lvl107

Could you explain the logical operation of R.rows(R) ??

tks

24-Ruby V
(To:KC_10577235)

R is a variable which ultimately contains the return value of the function (R ... Result, Return value), here its a vector.
When a variable is used in a program for the first time on the left hand side of a local assignment, it is automatically initialized with zero.
The rows(...) function, which actually returns the number of rows of a matrix, returns 0 for a scalar like 0. Therefore, the first time R[rows(R)<- ... creates a 1x1 matrix R. The next time rows(R) returns the value 1 and so with R[rows(R)<- ... another element is added to the vector R, etc.
However, the whole thing works only if the system variable ORIGIN has the value 0.
This is the reason why my function uses the expression ORIGIN+rows(R) instead of rows(R) (and I abbreviated ORIGIN in my program at the very beginning with O), so that the function also works in worksheets which use a different value for ORIGIN (many users set Origin to the value 1, so that with vectors the first element has the index 1 and not 0).

In short - R[rows(R) is a way to create a vector and add values without having to initialize the vector (which you would have to do in an extra step if you would use R <-- stack(R, ...) to add elements to the vector.

24-Ruby V
(To:KC_10577235)

Here is a generic utility function which interleaves two vectors of arbitrary lengths. They do not necessarily have to be the same length.

File in Prime 6 format attached

EDIT: Added a slighter shorter variant

16-Pearl
(To:KC_10577235)

This isn't better than the others already posted, just different.

Or a small variation:

Announcements
Top Tags