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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Column array with different assignment in even and odd rows

QS_10727930
4-Participant

Column array with different assignment in even and odd rows

Hello community


I request your help please with the following problem:

I need to run a for or similar loop that allows me to build a 1x (2N) array, where N is an input value.

That is, the array will always have an even number of rows. On each odd row the routine should place "Px" and on each even row the routine should place "Py".

 

QS_10727930_0-1688270396426.png

 

 

Thanking you in advance for your help

 

 

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:QS_10727930)

I made a mistake. You've set ORIGIN t0 1. My program needs a tweak.

 

Success!
Luc

 

View solution in original post

6 REPLIES 6
LucMeekes
23-Emerald III
(To:QS_10727930)

How about:

LucMeekes_0-1688279737889.png

Success!

Luc

QS_10727930
4-Participant
(To:LucMeekes)

It seems that the results are not obtained in the positions that it should. For example, 45 would have to be in row 5 and -20 in row 6 and the array should have only 2*N=2*12=24 rows

LucMeekes
23-Emerald III
(To:QS_10727930)

I made a mistake. You've set ORIGIN t0 1. My program needs a tweak.

 

Success!
Luc

 

I have tried this, pero it doesnt work....

QS_10727930_0-1688320318011.png

 


@QS_10727930 wrote:

I have tried this, pero it doesnt work....

QS_10727930_0-1688320318011.png

 


Hi,

MartinHanak_0-1688366529578.png

 


Martin Hanák
Werner_E
25-Diamond I
(To:QS_10727930)


@QS_10727930 wrote:

I have tried this, pero it doesnt work....

QS_10727930_0-1688320318011.png

 

 


Because your inner j-loop assigns N times an element of one of the input vectors to the very same element P[i,1 of the result vector. So at the end every P[i,1 ends up with the same last element of the input vector.

To fix this you would make the index of the assigned element in Px and Py dependent on i.

You don't need the j-loop. Its also not necessary to initially create the result vector P though doing so may speed up calculation for very large input vectors (which you sure won't provide via a Prime table).

I also like to define O <-- ORIGIN at the top of my programs. But I only do this when creating a utility function which might also be used in worksheets which have the system variable ORIGIN set to different values. Your program does not use O anywhere so you can omit that assignment.
For column vectors its not necessary to provide the second matrix index (column index), you can omit it

So one possible fix would be

Werner_E_0-1688386225495.png

 

Nonetheless I sure would prefer using an utility function like the one which Luc had provided and it sure makes sense making it ORIGIN independent as he did (see his corrected version).

There are many ways to skin a cat and so here are a few more variants of such a function for you to chose from

Werner_E_1-1688386365277.png

Feel free to assign O<--ORIGIN in the front of the programs and use O instead of ORIGIN to save some typing and space 😉

Prime 9 worksheet attached

Announcements

Top Tags