Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hi,
Is it possible to reset variables? For example, if I want to have one file with multiple different calculations inclduing a variable for diameter, is it possible to have a line break or something, so that any variables above it are not used? Therefore variable for diameter needs to be redefined again.
I know that just re-using the same variable redefines it, and that I could use D, D_1, D_2 and so on, but I do not find these acceptable solutions as it increases potential for calculating errors.
And sorry for asking this, I know this must be a common question, but I don't seem to be finding the old ones.
Solved! Go to Solution.
There are several potential ways to solve this problem.
The most direct method is to use the build-in Clear for functions, clear and clear.sym.
Is there a reason why simply assigning new values won't work?
Alternatively, you could write a function to encapsulate your equations. Your main variables could, for example, be passed to the function as its arguments, whilst any other variables could be defined locally within the function.
Unfortunately, I’m not near a PC at the moment, so can’t give examples.
Stuart
There are several potential ways to solve this problem.
The most direct method is to use the build-in Clear for functions, clear and clear.sym.
Is there a reason why simply assigning new values won't work?
Alternatively, you could write a function to encapsulate your equations. Your main variables could, for example, be passed to the function as its arguments, whilst any other variables could be defined locally within the function.
Unfortunately, I’m not near a PC at the moment, so can’t give examples.
Stuart
Thank you!
That's exactly what I needed. Would be slightly more convinient if it would clear everything without needing to type every variable, but it's easy enough to copy-paste.
Simply assigning new values works, but it introduces a very high risk for miscalculations. If you forgot to redefine something, it would not be immediately obvious that an incorrect value is being used. but if all variables are clered, it is obviously not possible to end up with wrong results.
Unfortunately any form of ALL, or * doesn't work to clear all variables.
Note that you can clear ORIGIN, but you cannot clear NaN:
Success!
Luc
Note that you can clear ORIGIN, but you cannot clear NaN:
Interesting!
I did not expect to be able to 'clear' NaN as NaN is used wherever a number is valid and you can't clear a number either..
But I would call it a bug that we can clear system variables like ORIGIN, TOL and CTOL!
And, yes, I also miss some kind of clearAll() and clearAll.sym().
BTW, trying to do this
seems to force Prime's calculation into and endless loop. So it's clearly a bug. Who's willing to officially report it to PTC?
Note that ORIGIN must be manually labelled as "System" for this to 'work' and that we use a vector index "3".
Trying to 'clear' a system variable should either throw an error or it should reset it to its default value (I'm not quite sure yet which of these I should consider more sensible).
