Convert string into greek letters

Hi,
I have edit text in GUI. If I write into edit text for example aplha, is possible to convert string into greek letter?

3 commentaires

Walter Roberson
Walter Roberson le 12 Juin 2012
That depends where the greek letters must appear.
john
john le 12 Juin 2012
:)
In matrix UserData.matrix.....is possible to convert string into greek letter and than insert into cell matrix? And also I will make symbolical and numerical calculations.
Now I am using this commands:
1. UserData.matrix(3,1)=num2cell(sym(get(handles.edit5,'string'))); % for load string in one part of code
2. UserData.info(4,1)=num2cell(sym(UserData.matrix{4,1})); % to print string in uitable, this code is in other part of code
3. D(4,1)=sym(UserData.info{4,1});
4. result(4,1)=cellstr(char(D(4,1))); % result is in uitable
john
john le 14 Juin 2012
Or is possible to convert data into greek letter for uitable? So in uitable will be greek letters.

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 14 Juin 2012

2 votes

Try for example
uitable('Data',num2cell(char(945:969).'))

24 commentaires

john
john le 14 Juin 2012
Sorry, this doesn't work
Walter Roberson
Walter Roberson le 14 Juin 2012
Works fine for me on Ubuntu 10.04 (Linux) under MATLAB R2007a, R2008b, R2010b
john
john le 16 Juin 2012
Here is my code:
h=findobj(0,'Type','figure','Tag','figure1');
UserData=get(h,'UserData');
function pushbutton12_Callback(hObject, eventdata, handles)
uitable('Data',num2cell(char(945:969).'))
set(h,'UserData',UserData);
guidata(hObject, handles);
Result of this code-in uitable will appear 25 rows with symbol square.
I have Matlab 7.12.0.635 (R2011a), Windows XP and also Vista. I don't know, what is wrong. Do I have make some settings in uitable properties?
Walter Roberson
Walter Roberson le 16 Juin 2012
Please check your system Regional Settings and see if you are set to a particular Code Page for your character set; please also let us know what Language you are set to.
The codes 945 to 969 are the Unicode codes for the lower-case greek characters. If you are set to a particular code page, they might be in a different place or they might not be available at all.
john
john le 18 Juin 2012
I don't know change "Change system locale", because my program has to work without changing of any Regional and Language Options. And I'm not sure, that I have to make some changes, because this code works correctly
text(.5,.5,texlabel('alpha)).
But, this is only for the text, and I need it for the uitable. :(
Walter Roberson
Walter Roberson le 18 Juin 2012
Try this:
foo = uitable('Data', {'<HTML>1+α'})
john
john le 18 Juin 2012
foo = uitable('Data', {'<HTML>1+α'}) works,
but all informations ( columns and rows ) I have in matrix result. How can I change your code to my situation?
Walter Roberson
Walter Roberson le 18 Juin 2012
Let S be your cell array to convert, and let each element of S be in char() form (you need an additional step if they are in sym form)
T = regexprep(S, 'alpha', 'α');
T = regexprep(T, 'beta', 'β');
T = regexprep(T, 'gamma', 'γ')
....
T = regexprep(T, 'omega', 'ω');
then set the uitable Data property to be T .
john
john le 20 Juin 2012
1. how can I group together command <HTML> and T.
.
.
T = regexprep(result(4,1), 'alpha', 'α')
t = uitable('Parent',f,'Data',{'<HTML>&',T})???
2. I need also index...for example, alpha23....number 23 has to be smaller than greek letter aplha
Walter Roberson
Walter Roberson le 20 Juin 2012
t = uitable('Parent', f, 'Data', strcat('<HTML>',T) )
For subscript 23, use
<SUB><FONT SIZE=-2>23
For example,
reppat = '$1;<SUB><FONT SIZE=-1>$2</FONT>/<SUB>';
T = regexprep(S, '(alpha)(\d+)', reppat);
T = regexprep(T, '(beta)(\d+)', reppat);
T = regexprep(T, '(gamma)(\d+)', reppat);
and so on.
john
john le 21 Juin 2012
1. t = uitable('Parent', f, 'Data', strcat('<HTML>',T) ) works great.
2. reppat = '$1;<SUB><FONT SIZE=-1>$2</FONT>/<SUB>';
T = regexprep(S, '(alpha)(\d+)', reppat);
....result is alpha;3/. Not greek letter. It can happen, that there will be alpha2beta4, so base on code in point 2. , than 2beta4 will be smaller chars, but beta has to be also bigger char. So this code is not so good.
Walter Roberson
Walter Roberson le 21 Juin 2012
Sorry, reppat should be
reppat = '&$1;<SUB><FONT SIZE=-1>$2</FONT></SUB>';
john
john le 21 Juin 2012
Do you know change you code? If I have for example Capacitor23, then Capacitor has big size of chars and 23 are smaller ? Do you knok do this?
john
john le 21 Juin 2012
And if I write only alpha, then code doesn't works, only with some number like alpha34
Walter Roberson
Walter Roberson le 21 Juin 2012
I think this should do it:
T = regexprep(S, '([A-Za-z]+)(\d+)', '$1<SUB><FONT SIZE=-1>$2</FONT></SUB>');
T = regexprep(T, '(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega', '&$1;', 'preservecase');
This should also handle upper-case greek letters.
john
john le 21 Juin 2012
It not possible what did you do :).
I little changed your code, but big thanks again.
Walter Roberson
Walter Roberson le 21 Juin 2012
Ah, I missed the close bracket after omega .
john
john le 25 Juin 2012
those greek letters works corretly :T = regexprep(T, '(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega|tau|equiv|otimes|cap|int|perp|ni|cong|oplus|cup|times|oslash|o|nabla)', '&$1;');
Other letters from http://www.clemson.edu/ces/crb/procedures/greek/mat_greek.htm doesn't work. For example, if I write varsigma, then I get &varsigma, not greek letter....where can be I problem?
Walter Roberson
Walter Roberson le 25 Juin 2012
varsigma is not an HTML character entity. HTML appears to call it sigmav . See http://www.w3.org/TR/WD-math-970515/table04.html
john
john le 25 Juin 2012
In code I use sigmav. What I should write into edit text for correct convert into greek letter? sigmav or varsigma? If I write sigmav, I get &sigmav. If I write varsigma, I get var and greek letter sigma. So, it is not good.
Walter Roberson
Walter Roberson le 25 Juin 2012
Modifié(e) : Walter Roberson le 1 Juil 2012
john
john le 1 Juil 2012
Modifié(e) : Walter Roberson le 1 Juil 2012
Hi, sigma and sigmaf are OK. But theta and thetasym not. If I write thetasym I get symbol theta + sym for this code
T = regexprep(T, '(Alpha|Beta|Gamma|Delta|Epsilon|Zeta|Eta|Theta|Iota|Kappa|Lambda|Mu|Nu|Xi|Omicron|Pi|Rho|Sigmaf|Sigma|Tau|Upsilon|Phi|Chi|Psi|Omega|alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigmaf|sigma|tau|upsilon|phi|chi|psi|omega|thetasym|upsih|piv)', '&$1;');
but for this code
T = regexprep(T, '(thetasym|piv)', '&$1;');
is OK, but I need code for all letters.
Hi,
could you help me please? This is me code:
vd=size(UserData.info);
for i= 0:vd(1)-4
T = regexprep(cellstr(char(sym(UserData.matrix{4+i,1}))), '([A-Za-z]+)(\d+)', '$1<FONT SIZE=-1>$2</FONT>');
T = regexprep(T, '(Alpha|Beta|Gamma|thetasym|piv|Delta|Epsilon|Zeta|Eta|Theta|Iota|Kappa|Lambda|Mu|Nu|Xi|Omicron|Pi|Rho|Sigmaf|Sigma|Tau|Upsilon|Phi|Chi|Psi|Omega|alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigmaf|sigma|tau|upsilon|phi|chi|psi|omega|upsih|lsquo|rsquo|sbquo|ldquo|rdquo|bdquo|dagger|Dagger|bull|hellip|permil|prime|Prime|lsaquo|rsaquo|oline|euro|trade|larr|uarr|rarr|darr|harr|crarr|loz|spades|clubs|hearts|diams|forall|part|exist|empty|nabla|isin|notin|ni|prod|sum|minus|lowast|radic|prop|infin|ang|and|or|cap|cup|int|sim|cong|asymp|ne|equiv|le|ge|sube|supe|sub|sup|nsub|oplus|otimes|perp|sdot)', '&$1;');
result(4+i,1)=strcat('<HTML>',T);
end;
Code makes: if I write for example U1U2, than all numbers are subscript. But I need phi2U2, than everything after "phi" must be subscript, so 2U2 must by subscript.
Thank you
john
john le 23 Avr 2013
Hi, how can I insert sqrt into uitable? for example sqrt(2).
Surd doesn't help.
Thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Labels and Annotations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by