问题
I'm working on a MATLAB program with a gui. I want to have text labels and buttons in french, but it doesn't work. For example, the word 'Paramètres' in the code becomes Paramètres on the gui.
I checked the file encoding and it's utf-8. What can I do to fix that?
Here's a simple example of one command that I used in the code:
tab2 = uitab('v0', hTabGroup, 'title','Paramètres des canaux');
Thanks.
回答1:
How about using HTML?:
figure
hTabGroup = uitabgroup;
drawnow;
tab2 = uitab('v0',hTabGroup,'title','<html>Paramètres des canaux</html>');
See here for a list of HTML character codes.
回答2:
To add an accent aigu use
title('{Param\''etres des canaux}','interpreter','latex')
To add an accent grave use
title('{Param\`etres des canaux}','interpreter','latex')
回答3:
I found the answer on this stackoverflow page. Basically, I just have to set MATLAB
encoding to UTF-8 before creating the GUI. The command is simply:
feature('DefaultCharacterSet','UTF-8');
and that's it!
回答4:
I was having difficulty copy-pasting the string from SO to MATLAB, as the "è" showed up as char(65533)
(instead of the correct char(232)
) for some reason...
Anyway, I threw together a small conversion utility to convert strings or cellstrings to their Unicode-in-HTML equivalent, to complement horchler's answer:
function html = toHTML(strings)
%% Initialize
% Basic IO check
if ~iscellstr(strings) && ~ischar(strings)
error(...
'toHTML:invalid_input',...
['Invalid input class: ''%s''.\n',...
'Supported input types are ''char'' or a ''cell'' containing ''char''.'], class(strings));
end
% Provide support for
% - Single and multiline line char arrays
% - Cellstrings
wasChar = ischar(strings);
if wasChar
if size(strings,1) > 1
strings(:, end+1) = char(10);
end
strings = {strings};
end
%% Convert all strings to their unicode representation in HTML
% Just for abbreviation
uf = {'UniformOutput',false};
% Convert all characters to their HTML unicode representation
html = cellfun(@transpose, strings, uf{:});
html = cellfun(@(x) cellstr(num2str(x(:)+0)), html, uf{:});
html = cellfun(@(x) cellfun(@(y) ['&#' strtrim(y) ';'],x, uf{:}), html, uf{:});
% Include HTML tags
html = cellfun(@(x) ['<html>' [x{:}] '</html>'], html, uf{:});
% Take care of newlining
html = regexprep(html, ' ', '<br>');
html = regexprep(html, '<br></html>$', '</html>');
% Make output type consistent with input type
if wasChar
html = [html{:}];
end
end
I'm currently submitting this to the FEX as well. If anyone knows whether such a thing exists already, please let me know.
回答5:
I've fixed this problem with this technique.
Write this in your terminal :
export LC_CTYPE="en_US.ISO-8859-1"
Then, launch Matlab and try :
title('été');
if that works, you only need to create a script that will execute the export command before launching Matlab. Either in your .bashrc file, a custom script launching Matlab, etc...
My workaround is simply to create a custom script (i.e. "mat" in my /home/username/bin directory) :
#!/bin/bash
cd /home/username/Matlab
export LC_CTYPE="en_US.ISO-8859-1"
/path/to/matlab/matlab
Then, I created an alias in the .bashrc file of the /home/username directory to launch the script "mat"
alias m="/home/proy/bin/mat &"
回答6:
If it's inside a matlab script you store your string with accentuated characters, try to change the encoding of your matlab script to ANSI (eg, with Notepad++ or SublimeText).
来源:https://stackoverflow.com/questions/17472026/french-accents-in-matlab-gui