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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

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.

6 Comments

Fang on 13 May 2013

when I input the sentence as following , I got:

double( str ) ans =

    63    63    63    63    63    63    10
Fang 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:

          säkerställa

the wrong words like:

          säkerställa
Walter Roberson on 14 May 2013

How are you doing the reading into a variable ?

Fang

Products

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.

However,

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

0 Comments

per isakson

Contact us