Skip to main content
13-Aquamarine
Aug 29, 2025 1:08 AM UTC
Solved

Loop G rows of a matrix

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.

Werner_E
Werner_EAnswer
25-Diamond I
Aug 29, 2025 4:03 AM UTC

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

 

 

5 replies

13-Aquamarine
Aug 29, 2025 1:09 AM UTC

Program attached.

Translate
terryhendicott
21-Topaz II
Aug 29, 2025 1:18 AM UTC

Hi,

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

Use the submatrix() function.

 

Capture.JPG

Cheers

Terry

Translate
13-Aquamarine
Aug 29, 2025 2:23 AM UTC

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

Translate
Werner_E
Werner_E25-Diamond IAnswer
25-Diamond I
Aug 29, 2025 4:03 AM UTC

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

 

 

Translate
13-Aquamarine
Aug 29, 2025 2:44 PM UTC

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.

Translate