2

I'm plotting some of my analysis results in Matlab. My operating system is Ubuntu 13.10. I try to add the letter "ä" into the title of Matlab figure, but what I get is the following:

enter image description here

here is my code:

function plotResults(data)
% FUNCTION plotResults(data)

ind = 1;
x = 1:length(data{1, end});

for i = 1:length(data)
    if mod(i, 5) == 1
        figure(ind)
        plot(x, data{i, end}, 'b--')
        hold on
    elseif mod(i, 5) == 2
        plot(x, data{i, end}, 'c--')
    elseif mod(i, 5) == 3
        plot(x, data{i, end}, 'r--')
    elseif mod(i, 5) == 4
        plot(x, data{i, end}, 'g--')
    elseif mod(i, 5) == 0
        plot(x, data{i, end}, 'm--')
        legend('Random', 'Hill climb', 'Greedy hill climb', 'Stochastic hill climb', 'Hill climb --> Stochastic hill climb')
        grid on
        xlabel('Aika')
        ylabel('Kustannus')
        title(['Käsiä : ' num2str(data{i, 2}) ', Suuttimia : ' num2str(data{i, 3})])
        ind = ind + 1;
    end
end

Any idea how to get the "ä" show up correctly? =)

Thnx for any help!

P.S.

MWE:

plot(1:10, 1:10)
title(['{\"a}{\"o} ' num2str(5) ], 'Interpreter', 'latex')
jjepsuomi
  • 4,223
  • 8
  • 46
  • 74

1 Answers1

3

You can use LaTeX:

title(['K\"asi\"a : ' num2str(data{i, 2}) ', Suuttimia : ' num2str(data{i, 3})])

See Is it possible to display unicode in MATLAB plot labels? and How to write “ä” and other umlauts and accented letters in bibliography?

Or try the unicode approach:

title(['K', char(228), 'si', char(228) : ' ....
Community
  • 1
  • 1
Dan
  • 45,079
  • 17
  • 88
  • 157
  • +1 Thank you for your help! =) Unfortunately didn't work...Now instead of the funny symbols in the image above it printed "\a. {\"a} also didn't do it. It just prints {\"a}.... – jjepsuomi Mar 07 '14 at 06:37
  • +1 Your links led me to the answer, thank you =) I need to set 'Interpreter', 'latex' in the title-command =) – jjepsuomi Mar 07 '14 at 06:51
  • 1
    Try adding `,'interpreter','tex'` to the end of your `title` function – Dan Mar 07 '14 at 06:51
  • +1 Yes, it did it =) The letter 5 looks a bit funny (maybe Ubuntu has something to do with it, because the plots look different in Ubuntu Matlab than Windows Matlab). but ä and ö are working =) Oh by the way @Dan 'tex' didn't work for me, it needed to be 'latex' – jjepsuomi Mar 07 '14 at 06:52
  • 1
    Hmmm.. how about `['K$$\"a$$si$$\"a$$ : ' num2str(data{i, 2}) ', Suu...`? Or else you might try the unicode approach? – Dan Mar 07 '14 at 06:54
  • the $$ approach did not do it, Matlab gave: Warning: Unable to interpret LaTeX string "K$$\"a$$si$$\"a$$ : 5, Suuttimia : 5" – jjepsuomi Mar 07 '14 at 06:57
  • @jjepsuomi try the unicode way, just posted an example – Dan Mar 07 '14 at 06:58
  • Sorry, unicode didn't do it either, it gave the same results as the original approach. I posted minimal working example, which mimics my title code =) – jjepsuomi Mar 07 '14 at 07:01
  • I think I'll go with 'Interpreter', 'latex'-approach, it seems the best so far =) Not perfect (because it makes 5 look funny), but I'll live with it =) Thank you for your effort – jjepsuomi Mar 07 '14 at 07:06