cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

How to change and append matrix items of a globaly defined matrix via program?

pklemm-2
6-Contributor

How to change and append matrix items of a globaly defined matrix via program?

I want to create a global result table with fixed columns. From anywhere behind the definition of that table I will insert new result lines or modify existing rows. For modification, the first column is a key column, so that the match-Function could give back the row number:

My problem is, that the ResultTable will not be changed. Also not if I write

ResultTable:=AddResult("key123","Cap1","that's a nice result",4.5)

Yes, I know that inside a program the assignments are local. How to make global?

Thank for help!

ACCEPTED SOLUTION

Accepted Solutions
StuartBruff
23-Emerald III
(To:pklemm-2)

You have to pass ResultTable as an argument to AdddResult.

Stuart

View solution in original post

6 REPLIES 6
StuartBruff
23-Emerald III
(To:pklemm-2)

You have to pass ResultTable as an argument to AdddResult.

Stuart

pklemm-2
6-Contributor
(To:StuartBruff)

Thank you, Stuart

yes that works in that way:

ResultTable:=AddResult(ResultTable,other arguments)

but is there no possibility to change global variables directly?

Werner_E
25-Diamond I
(To:pklemm-2)

> but is there no possibility to change global variables directly?

No. The first time you use ResultTable on the LHS of an assignment in your program you automatically create a local variable with that very name and all subsequent calculations are done using this local variable. So you can't change a worksheet variable from within a program the way you tried to do.

In Mathcad 15 there may be a way of doing it using scripted component - not sure about that and not available in Prime anyway.

R

RichardJ
19-Tanzanite
(To:Werner_E)

In Mathcad 15 there may be a way of doing it using scripted component - not sure about that and not available in Prime anyway.

That can indeed be done in MC15. However, as you say, it's not a solution for Prime.

StuartBruff
23-Emerald III
(To:pklemm-2)

Peter Klemm wrote:

Thank you, Stuart

yes that works in that way:

ResultTable:=AddResult(ResultTable,other arguments)

but is there no possibility to change global variables directly?

Well, possibly there is a way ... it works in Mathcad 15 but it's an undocumented feature.  I think it still works in Prime 3.1, but I'm not sure and don't have Prime available to check.   It makes use of a "feature" (aka "bug" ... but maybe not) that allows a function to create a closure around an array, which provides a means for updating the array.  It needs careful handling and the worksheet should be written and then calculated as a whole to make sure that all evaluations are carried out in the intended order.

Here's an example based around a Fibonacci function ...

Stuart

pklemm-2
6-Contributor
(To:StuartBruff)

Thanks again.

I will try it.

Announcements

Top Tags