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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

The array order reassign

Kocela
8-Gravel

The array order reassign

Hi Masters

How to reassign the array elements order??

tks

KC_10577235_0-1676297286626.png

 

 

ACCEPTED SOLUTION

Accepted Solutions
lvl107
20-Turquoise
(To:lvl107)

2.PNG

   Best Regards.

View solution in original post

8 REPLIES 8
Werner_E
25-Diamond I
(To:Kocela)

Use C:=stack(A,B)

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

lvl107
20-Turquoise
(To:Kocela)

It seems like this :

1.PNG

Best Regards.

   Loi.

lvl107
20-Turquoise
(To:lvl107)

2.PNG

   Best Regards.

Werner_E
25-Diamond I
(To:lvl107)

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

Kocela
8-Gravel
(To:lvl107)

Hi Lvl107

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

tks

 

 

Werner_E
25-Diamond I
(To:Kocela)

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.

Werner_E
25-Diamond I
(To:Kocela)

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

Werner_E_0-1676310554456.png

File in Prime 6 format attached

 

EDIT: Added a slighter shorter variant

Werner_E_0-1676311116288.png

 

 

DJF
16-Pearl
16-Pearl
(To:Kocela)

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

 

2023-02-13_14-40-07.png

Or a small variation:

2023-02-13_14-43-57.png

Announcements

Top Tags