3

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.

user2482876
  • 288
  • 4
  • 15
  • Well if it helps; on `Matlab R2013a` everything works fine even `uitab`. Can you just try `title('Paramètres des canaux')` when all the figures are closed? – p8me Jul 04 '13 at 14:08
  • 1
    I'm using `Matlab R2010a` and your command `title('Paramètres des canaux')` causes the same accent display problem. The title says 'Paramètres des canaux'. – user2482876 Jul 04 '13 at 14:16

6 Answers6

2

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.

horchler
  • 18,384
  • 4
  • 37
  • 73
  • Yep, that does it! A bit annoying to rewrite everything in html, but if it works, it's worth it. Thanks! – user2482876 Jul 04 '13 at 15:29
  • I don't have any experience with these things, but FYI, in R2012b I get this warning- Warning: The uitabgroup object is undocumented and some of its properties will become obsolete in a future release. – horchler Jul 04 '13 at 15:30
  • Ok, so doesn't really works. It works for my tab2 but not my tab1. Weird. – user2482876 Jul 04 '13 at 15:35
  • You might ask your question over at [MatlabCentral](http://www.mathworks.com/matlabcentral/) as well (yes, all of MathWorks.com is down at the moment). Yair Altman, who has [blogged about uitab](http://undocumentedmatlab.com/blog/uitab-colors-icons-images/) in the past, occasionally responds to queries over there. – horchler Jul 04 '13 at 15:42
1

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')
Colorless Photon
  • 399
  • 1
  • 3
  • 19
1

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!

Community
  • 1
  • 1
user2482876
  • 288
  • 4
  • 15
  • unfortunately, the problem persists (in R2010a). – Rody Oldenhuis Jul 05 '13 at 11:15
  • @RodyOldenhuis : Well, I'm using `MATLAB R2010a` and this works for me. The only thing is that sometime I have to pass the command twice for it to work. – user2482876 Jul 05 '13 at 14:19
  • Try this: `for ii=1:30, feature('DefaultCharacterSet','UTF-8'); end; title(['Param' char(232) 'tres des canaux']);` – Rody Oldenhuis Jul 05 '13 at 14:27
  • @RodyOldenhuis : I don't use the `char()`command. I use the real character directly. for me, this works: `feature('DefaultCharacterSet','UTF-8'); title('Paramètres des canaux');` – user2482876 Jul 05 '13 at 15:15
  • well...not here. Those characters should be the same btw...Are you on Windows? Linux? – Rody Oldenhuis Jul 05 '13 at 15:25
  • @RodyOldenhuis : I'm on OSX. This is a weird behaviour. – user2482876 Jul 05 '13 at 16:05
  • Chouette! Does the character stay fixed if you reset the `'DefaultCharacterSet'` back to `'ISO-8859-1'` after you're done creating the GUI? I wonder which character set you were using testing `char(232)`? On R2012b (and OS X) one needs to use `feature('DefaultCharacterSet','ISO-8859-1')` or you get `'è'`. – horchler Jul 06 '13 at 22:44
  • @horchler: I suppose it stay fixed until you update the object. I think I was using the `ISO-8859-1` character set while testing `char(232)`. – user2482876 Jul 08 '13 at 14:09
  • I just realized that it never works on the first try even if I pass the `feature` command twice. It only works after I close and relaunch the figure. Annoying. – user2482876 Jul 10 '13 at 17:52
0

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.

Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
0

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 &"
Balinus
  • 111
  • 4
0

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

gaborous
  • 15,832
  • 10
  • 83
  • 102