How can i use a symbol as a variable ?
46 views (last 30 days)
Show older comments
Mallouli Marwa on 7 Apr 2017
Commented: Walter Roberson on 20 Feb 2023 at 7:00
I want to define a varibale alpha_ks as a symbol \alpha_ks but an error will be appeared.
function [a, x, ...]= MFC ()
dbmn on 7 Apr 2017
If you want to display nice formulas, you could do so in the new live scripts.
In the (text based) code it doesn't make sense.
dpb on 7 Apr 2017
Edited: dpb on 7 Apr 2017
... valid variable name is a character string of letters, digits and
underscores, with ... the first character a letter, ...
While an (extended) character, '\alpha_ks' is not in the set of letters, digits, underscores. Ergo, it can't be a variable name by itself nor even as part of a longer name within which it occurs. "Sometimes we just can't have everything we want."
Another comment mentioned it having to do with text-based code which isn't really the issue; the restriction is that Matlab is based on the C/C++ coding language internally and these are the same rules for valid variable names in C. Nothing says TMW couldn't have expanded the allowable character set inside the Matlab interpreter, but would add another parsing overhead step as any variable name outside the naming rules would have to have another internal name generated for it that would follow the internal coding rules; potentially another real speed bottleneck when also would need to translate that back for display. Much easier to just follow the rules as they exist despite the lack of being able to write code that looks as much like the algebra of the underlying expression as might like. I suspect these kinds of restrictions will loosen significantly over time, but "not yet".
Walter Roberson on 20 Feb 2023 at 7:00
Back in 2017, most versions of MATLAB did not use UTF8 encoding for the file, and so only 8 bit codes that did not use the UTF control sequences could be reliably used... and even then only if there was no conflicting 8 bit code. For this purpose a conflicting code would be punctuation in one character set but letter-like in another character set: with 8 bit codes you would not be able to tell which is which. It does not matter if in one character set 0xC3 is 'Ă' but it is 'Ä' in a different character set: you could treat both as letters. It would matter if a character was Ϋ in one character set but … (ellipsis) in a different character set as those have different roles and … would probably be expected to act the same way as ... (three periods)
Find more on Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!