Skip to main content
13-Aquamarine
August 29, 2025
Solved

Loop G rows of a matrix

  • August 29, 2025
  • 2 replies
  • 640 views

I'm trying to pull G number of rows from an array.  The For loop is not working.  It gives me the whole array instead.

Best answer by Werner_E

In your attempt you never access a single row of the matrix. Here some comments:

Werner_E_1-1756440812859.png

 

I assume that when G=3 you want the program to return the top three rows of your matrix - independent from the setting of ORIGIN.

If you insist on using a for-loop you could do it that way using the row operator:

Werner_E_0-1756439809750.png

Personally I would prefer using a more generic utility function where the number of rows is an additional function argument:

Werner_E_1-1756439926771.png

But what exactly do you have against the "submatrix" function?

Werner_E_2-1756440082104.png

 

P11 file attached

 

 

2 replies

13-Aquamarine
August 29, 2025

Program attached.

21-Topaz II
August 29, 2025

Hi,

ORIGIN is set to default of 0.  G=3 means fourth row.

Use the submatrix() function.

 

Capture.JPG

Cheers

Terry

13-Aquamarine
August 29, 2025

Yeah,  I did the same.  I thought I should be able to do the same with a for loop.

Werner_E25-Diamond IAnswer
25-Diamond I
August 29, 2025

In your attempt you never access a single row of the matrix. Here some comments:

Werner_E_1-1756440812859.png

 

I assume that when G=3 you want the program to return the top three rows of your matrix - independent from the setting of ORIGIN.

If you insist on using a for-loop you could do it that way using the row operator:

Werner_E_0-1756439809750.png

Personally I would prefer using a more generic utility function where the number of rows is an additional function argument:

Werner_E_1-1756439926771.png

But what exactly do you have against the "submatrix" function?

Werner_E_2-1756440082104.png

 

P11 file attached

 

 

13-Aquamarine
August 29, 2025

Thank You. I like the method of calling out the number of rows in the function's argument.  

 

Nothing against the submatrix command.  But your programming is more intuitive for me.