フィルターのクリア

Why french accents are not represented correctly after Matlab2011b?

2 ビュー (過去 30 日間)
Marc Raventós Tato
Marc Raventós Tato 2023 年 2 月 24 日
回答済み: Marc Raventós Tato 2023 年 2 月 24 日
I am mantaining a piece of software developed on Matlab R2011b which uses several languages, french among them.
I am now compiling the code on Matlab R2022 and the non ASCII characters are represented either as or some other strange symbol.
However this does not happen when I run the code directly from the Matlab IDE, only running the executable.
Menu after compiling:
Menu when running the code from the IDE:
When I run feature('DefaultCharacterSet') on my command bar it says 'UTF-8', but I', not sure if that is relevant. I tried running some variations of this command, but it had no effect.
  3 件のコメント
Bruno Luong
Bruno Luong 2023 年 2 月 24 日
@Rik the source file is not the problem since it works under IDE
Rik
Rik 2023 年 2 月 24 日
I have gotten into the habit of specifying everything that is >127 and using a function like the one below to make sure my characters show up as expected. I haven't had any issues since, but your mileage may vary.
This code first checks the encoding of the char datatype (UTF-16 for Matlab, UTF-8 for Octave (for now)), and then dec2bin/bin2dec to do the encoding.
I minified the code (and removed unreachable warning text) to make it reasonably fit in a post like this.
function str=ch_r(dbl)
% This allows easy conversion from double to char, where you would normally use code like this:
% msg = ['This is the euro symbol: ' ch_r(8364)];
% This function works for Matlab and GNU Octave.
str=ch_r_f03(dbl,~ch_r_f00);
end
function v000=ch_r_f00,persistent v001,if isempty(v001),if ch_r_f01('<',0,'Octave','>',0),v002=...
struct('w',warning('off','all'));[v002.msg,v002.ID]=lastwarn;v001=~isequal(8364,...
double(char(8364)));warning(v002.w);lastwarn(v002.msg,v002.ID);else,v001=false;end,end,v000=...
v001;end
function v000=ch_r_f01(v001,v002,v003,v004,v005),persistent v006 v007 v008,if isempty(v006),...
v008=exist('OCTAVE_VERSION','builtin');v006=[100,1] * sscanf(version,'%d.%d',2);v007={};end,if ...
v008,if nargin==2,warning('HJW:ifversion:NoOctaveTest','x'),if isnumeric(v002),v009=...
0.1*v002+0.9*fix(v002);v009=round(100*v009);else,v010=ismember(v007(:,1),v002);if sum(v010)~=1,...
warning('HJW:ifversion:NotInDict','x'),v000=NaN;return,else,v009=v007{v010,2};end,end,elseif ...
nargin==4,[v001,v009]=deal(v003,v004);v009=0.1*v009+0.9*fix(v009);v009=round(100*v009);else,...
[v001,v009]=deal(v004,v005);v009=0.1*v009+0.9*fix(v009);v009=round(100*v009);end,else,if ...
isnumeric(v002),v009=0.1*v002+0.9*fix(v002);v009=round(100*v009);else,v010=ismember(v007(:,1),...
v002);if sum(v010)~=1,warning('HJW:ifversion:NotInDict','x'),v000=NaN;return,else,v009=...
v007{v010,2};end,end,end,switch v001,case'==',v000=v006==v009;case'<',v000=v006 < v009;case'<=',...
v000=v006 <=v009;case'>',v000=v006 > v009;case'>=',v000=v006 >=v009;end,end
function v000=ch_r_f02(v001),if numel(v001)>1,error('x'),end,if v001<128,v000=v001;return,end,...
persistent v002,if isempty(v002),v002=struct;v002.limits.lower=hex2dec({'0000','0080','0800',...
'10000'});v002.limits.upper=hex2dec({'007F','07FF','FFFF','10FFFF'});v002.scheme{2}=...
'110xxxxx10xxxxxx';v002.scheme{2}=reshape(v002.scheme{2}.',8,2);v002.scheme{3}=...
'1110xxxx10xxxxxx10xxxxxx';v002.scheme{3}=reshape(v002.scheme{3}.',8,3);v002.scheme{4}=...
'11110xxx10xxxxxx10xxxxxx10xxxxxx';v002.scheme{4}=reshape(v002.scheme{4}.',8,4);for v003=2:4,...
v002.scheme_pos{v003}=find(v002.scheme{v003}=='x');v002.bits(v003)=numel(v002.scheme_pos{v003});
end,end,v004=find(v002.limits.lower<=v001&v001<=v002.limits.upper);v000=v002.scheme{v004};v005=...
v002.scheme_pos{v004};v003=dec2bin(double(v001),v002.bits(v004));v000(v005)=v003;v000=...
bin2dec(v000.').';end
function v000=ch_r_f03(v001,v002),persistent v003,if isempty(v003),v003=ch_r_f01('<',0,'Octave',...
'>',0);end,if nargin==1,v002=~ch_r_f00;end,if v002,if all(v001<65536),v000=uint16(v001);v000=...
reshape(v000,1,numel(v000));else,[v004,v005,v006]=unique(v001);v000=cell(1,numel(v001));for ...
v007=1:numel(v004),v008=ch_r_f04(v004(v007));v008=uint16(v008);v000(v006==v007)={v008};end,v000=...
cell2mat(v000);end,if~v003,v000=char(v000);end,else,if all(v001<128),v000=char(v001);v000=...
reshape(v000,1,numel(v000));else,[v004,v005,v006]=unique(v001);v000=cell(1,numel(v001));for ...
v007=1:numel(v004),v008=ch_r_f02(v004(v007));v008=uint8(v008);v000(v006==v007)={v008};end,v000=...
cell2mat(v000);v000=char(v000);end,end,end
function v000=ch_r_f04(v001),if v001<65536,v000=v001;return,end,v002=double(v001)-65536;v002=...
dec2bin(v002,20);v000=bin2dec(['110110' v002(1:10);'110111' v002(11:20)]).';end

サインインしてコメントする。

採用された回答

Marc Raventós Tato
Marc Raventós Tato 2023 年 2 月 24 日
Thanks @Rik, it worked by changing the encoding of the .m file where the text was stored from ANSI to UTF-8!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by