MATLAB Answers


How can I deal with swedish words in matlab.

Asked by Fang
on 8 May 2013

Now when I read a .txt file with swedish words into matlab and then output it, all the swedish words became garbled. How can I make my matlab support swedish? Thanks in advance.


on 13 May 2013

when I input the sentence as following , I got:

double( str ) ans =

    63    63    63    63    63    63    10
on 13 May 2013

I change the OS option to swedish, then I got right swedish in command. But if I read swedish string into a variable in the matlab program and then print the variable in command, it will be wrong again. like:

the original words:


the wrong words like:


How are you doing the reading into a variable ?


No products are associated with this question.

1 Answer

Answer by per isakson
on 14 May 2013
Edited by per isakson
on 7 Jun 2013

Joel on Software wrote The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

A little experiment:

  • I wrote "ÅÄÖåäö" in UTF-8 with Notepad++ and saved as swedish.txt
  • I used fileread to read the file
    >> fileread( 'swedish.txt' )
    ans =
  • I converted my text to ANSI and
    >> fileread( 'swedish.txt' )
    ans =

Thus, I think you read from a file encoded with UTF-8.

See the documentation on fopen. With the correct setting "any" coding can be decoded.


    >> sprintf( '%s\n', 'ÅÄÖåäö' )
    ans =


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!