Why symvar() sort 10 smaller than 9

2 Ansichten (letzte 30 Tage)
Chen Bo-Yang
Chen Bo-Yang am 9 Apr. 2021
Kommentiert: Walter Roberson am 12 Apr. 2021
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 9 Apr. 2021
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])
ans = 
and '1' is before '2' in unicode, so X1anything occurs before X2anything
  2 Kommentare
Chen Bo-Yang
Chen Bo-Yang am 11 Apr. 2021
Thanks for your answer and I use sort() to solve my problem.
Walter Roberson
Walter Roberson am 12 Apr. 2021
sort() will sort by unicode code point -- but at least sort() would be consistent about what happens if you mix numbers and underscores.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by