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

Translate the entire conversation x

Beginner question: Why does a program "forget" array assignment when returning the result?

HP_1364456
10-Marble

Beginner question: Why does a program "forget" array assignment when returning the result?

Why does this element by element assignment not work?
MathCAD array Screenshot 2025-08-08 140920.png

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:HP_1364456)

"length" gives you the number of entries in a vector (BTW "rows" would yield the same result).

That way your loop reads

Werner_E_0-1754657371468.png

and  "loops" just from 3 to 3. The only value "i" is assigned is 3.

Its the same as

Werner_E_0-1754658013667.png

So you just define element with index 3 of your vector. If you do so, by default the other entries with lower indices are set to zero, like

Werner_E_1-1754657492150.png

In this example the value of ORIGIN was not changed and is at its default value 0. So the element with index 3 is the fourth vector entry. In your sheet you obviously had set ORIGIN to 1.

So what you meant was

Werner_E_2-1754657598860.png

The loop start at 1, which is the value of ORIGIN in your sheet, and ends at length(e)=3 (which is only the index of the last vector element if ORIGIN is set to 1)

 

A better approach would be

Werner_E_3-1754657636792.png

because its independent from the setting of ORIGIN.

The "last" function returns the index of the last vector element, taking into account the value of ORIGIN.

 

 

 

 

View solution in original post

3 REPLIES 3
Werner_E
25-Diamond I
(To:HP_1364456)

"length" gives you the number of entries in a vector (BTW "rows" would yield the same result).

That way your loop reads

Werner_E_0-1754657371468.png

and  "loops" just from 3 to 3. The only value "i" is assigned is 3.

Its the same as

Werner_E_0-1754658013667.png

So you just define element with index 3 of your vector. If you do so, by default the other entries with lower indices are set to zero, like

Werner_E_1-1754657492150.png

In this example the value of ORIGIN was not changed and is at its default value 0. So the element with index 3 is the fourth vector entry. In your sheet you obviously had set ORIGIN to 1.

So what you meant was

Werner_E_2-1754657598860.png

The loop start at 1, which is the value of ORIGIN in your sheet, and ends at length(e)=3 (which is only the index of the last vector element if ORIGIN is set to 1)

 

A better approach would be

Werner_E_3-1754657636792.png

because its independent from the setting of ORIGIN.

The "last" function returns the index of the last vector element, taking into account the value of ORIGIN.

 

 

 

 

Of course. Silly me. I actually have used that construct a couple of times earlier, it just hasn’t become part of “muscle memory” yet.

Thank you for quick reply!

Werner_E
25-Diamond I
(To:HP_1364456)

No problem.

You may consider closing the thread if there are no follow up questions.

For future questions I would suggest that you attach your worksheet (even though its just as small as here) and also state which version of Prime you are using.

Announcements

Top Tags