French accents in MATLAB gui

北战南征 提交于 2019-12-05 21:36:31

How about using HTML?:

figure
hTabGroup = uitabgroup;
drawnow;
tab2 = uitab('v0',hTabGroup,'title','<html>Param&egrave;tres des canaux</html>');

See here for a list of HTML character codes.

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')
user2482876

I found the answer on this stackoverflow page. Basically, I just have to set MATLABencoding to UTF-8 before creating the GUI. The command is simply:

feature('DefaultCharacterSet','UTF-8');

and that's it!

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, '&#10;', '<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.

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 &"

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!