필터 지우기
필터 지우기

2byte 文字を認識する

조회 수: 7 (최근 30일)
fumio hakamada
fumio hakamada 2020년 7월 6일
답변: michio 2020년 7월 7일
下の例でq2.txt2行目には空白の2バイト文字が間違って入っています。
str2numではこれを無視するようです。データの2行目は無視されます。警告も出しません。
データに2バイト文字が含まれることを認識して警告を出す方法はありますか?
%e81.m
fileID = fopen('q2.txt');
c = [];
while(1)
tline = fgetl(fileID);
if tline<0 break; end
b = str2num(tline);
c = [c,b];
if isempty(tline) fprintf(" blank line\n"); % advised
else fprintf("line=<%s>\n",tline); end
end
fclose(fileID);
c
%{
%q2.txt
1 1
2  2
3 3 3
4
5
%}

채택된 답변

michio
michio 2020년 7월 7일
b = unicode2native(tline);
length(b)
と unicode2native 関数を使った後の b の配列長さ(length(b) )で判別できるかもしれません。
いかがでしょうか。

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB 入門에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!