Skip to main content
Solved

index a column in array in zpl

  • 17 July 2024
  • 1 reply
  • 44 views

If I have a 2D array e.g. 10x2  A(x,y), what’s the syntax to extract one column (or row) in that array so that it’s a 1D array?

I’ve tried:

col = A(1:10,3)

col = A(:,3)

1 reply

Userlevel 7
Badge +2

@s.ng 

 

Unfortunately, ZPL doesn’t support slicing as you have tried as far as I know. Instead, you will have to do the slicing inside a loop. Something like so:

DECLARE an_array, INTEGER, 2, 10, 2

FOR jj, 1, 2, 1
FOR ii, 1, 10, 1
an_array(ii, jj) = ii + (jj-1)*10
NEXT
NEXT

DECLARE a_vector, INTEGER, 1, 10, 1

jj = 2

FOR ii, 1, 10, 1
a_vector(ii) = an_array(ii, jj)
NEXT

FOR ii, 1, 10, 1
PRINT a_vector(ii)
NEXT

RELEASE a_vector
RELEASE an_array

If you require more advanced programming features, I strongly suggest to look into the ZOS-API.

Take care,


David

Reply