'How can I sort a list/matrix in a function?
When I try to use SortA
and SortD
in a function:
Define test()=
Func
© Convoluted way of returning [0 1 2 4 5; 4 1 3 5 2]
Local a,b
a:=[1 5 2 0 4]
b:=[1 2 3 4 5]
SortA a,b
Return colAugment(a,b)
EndFunc
I get the error Invalid in a function or current expression
. I think this is because SortA
modifies variables and this isn't allowed in a function, only in a program. Is there a way to sort a list or matrix in this way in a function?
Solution 1:[1]
All you have to do is declare b as a local variable (as well as a):
Local a,b
And then it shouldn't return the error you mentioned.
I hope that helped!
Solution 2:[2]
The function SortA, SortD appears to work fine on the App calculator, and as a Program, but not with in a function.
Check this and correct a few mistakes Regards
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Logan Tischler |
Solution 2 | GBR |