简体   繁体   English

如何在函数中对列表/矩阵进行排序?

[英]How can I sort a list/matrix in a function?

When I try to use SortA and SortD in a function:当我尝试在函数中使用SortASortD时:

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 .我收到错误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.我认为这是因为SortA修改了变量,这在函数中是不允许的,只能在程序中使用。 Is there a way to sort a list or matrix in this way in a function?有没有办法在函数中以这种方式对列表或矩阵进行排序?

All you have to do is declare b as a local variable (as well as a):您所要做的就是将 b 声明为局部变量(以及 a):

Local a,b

And then it shouldn't return the error you mentioned.然后它不应该返回您提到的错误。

I hope that helped!我希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM