V
V
Vladimir Malin2018-12-20 12:46:25
Character encoding
Vladimir Malin, 2018-12-20 12:46:25

matlab. Import data from MS SQL. Encoding. How to implement?

The essence of the question is simple to triviality, but for the second day I can not understand the logic - how it is necessary to work.
A simple query to a data table containing Cyrillic characters:

%Make connection to database.  Note that the password has been omitted.
%Using ODBC driver.
conn = database('Test', '', '');
%Read data from database.
st = 'select top 10 * from main';
data = fetch(conn, st);
c = data.F(1)

The result, in theory, should be like this:
5c1b6211a9354033617807.png
In fact, we get the following result:
5c1b62758d352005374740.png
Reading the instructions directs to:
If you run into problems with corrupted characters, for example when using MATLAB files associated with a model, try using the slCharacterEncoding function to change the character encoding.

but using different combinations
% encoding='windows-1251';
%slCharacterEncoding(encoding);

Still leads to the same result as above.
Logically, it would be necessary to change the encoding of the data returned by the ODBC connection, but I can't figure out how to do this.
Maybe I'm digging in the wrong steppe at all?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Artyom Karetnikov, 2018-12-20
@Vmalin

It doesn't look like unicode. It looks like a classic windows cant and even has nothing to do with ODBC.
Try on another computer to create a file with encoding 1251, text and open it on this one. If you see the same thing - dig "locale settings". For each Windows there is a solution.

K
Konstantin Tsvetkov, 2018-12-20
@tsklab

If you have an NVARCHAR (UNICODE) field you need: Convert Unicode .

D
d-stream, 2018-12-20
@d-stream

It is not at all clear what type of fields are in the database.
so the poke method is:

select top 100
f=cast(f as nvarchar) ,
I=cast(I as varchar)
from main

V
Vladimir Malin, 2018-12-24
@Vmalin

Artem Karetnikov was right. In my case, the situation turned out to be that I had English in the system settings. More specifically:
Control Panel - Regional Options - Advanced tab - Language for non-Unicode programs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question