Why symvar() sort 10 smaller than 9
2 次查看(过去 30 天)
显示 更早的评论
My variables is X = X1 X2 ... X9 X10,but when I use symvar(X),I get X1 X10 X2 ... X9。
How can I sort it from small to large?
0 个评论
采纳的回答
Walter Roberson
2021-4-9
symvar() sorts inconsistently if I recall correctly. It gets complicated when you start mixing numbers and underscores.
For the simple case that does not involve underscores, symvar() sorts by unicode code point
alpha = evalin(symengine, '`α`'); %unicode U+03B1
lambda = evalin(symengine, '`λ`'); %unicode U+03BB
beta = evalin(symengine, '`β`'); %unicode U+03B2
chi = evalin(symengine, '`χ`'); %unicode U+03C7
symvar([alpha,chi,lambda,beta])
and '1' is before '2' in unicode, so X1anything occurs before X2anything
2 个评论
Walter Roberson
2021-4-12
sort() will sort by unicode code point -- but at least sort() would be consistent about what happens if you mix numbers and underscores.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!