Skip to main content
Solved

index a column in array in zpl

  • July 17, 2024
  • 1 reply
  • 79 views

s.ng
  • Monochrome
  • 4 replies

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)

Best answer by David.Nguyen

@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

View original
Did this topic help you find an answer to your question?

1 reply

David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1072 replies
  • Answer
  • July 18, 2024

@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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings