私はこの列のようなテキストファイルを持っています:
0,472412
0,455627
0,439148
0,421753
...
0,116577
0,086670
0,057373
0,027161
matlabでコンマをドットに変換するにはどうすればよいですか?
私はこの列のようなテキストファイルを持っています:
0,472412
0,455627
0,439148
0,421753
...
0,116577
0,086670
0,057373
0,027161
matlabでコンマをドットに変換するにはどうすればよいですか?
Matlabs サイトのこの投稿は、次のことを示唆しています。
function comma2point_overwrite( filespec )
% replaces all occurences of comma (",") with point (".") in a text-file.
% Note that the file is overwritten, which is the price for high speed.
file = memmapfile( filespec, 'writable', true );
comma = uint8(',');
point = uint8('.');
file.Data( transpose( file.Data==comma) ) = point;
delete(file)
end
...またはこれを行うことができます:
wholefile = fileread('yourfile.txt') % read in entire file
newfiledata = strrep(wholefile,',','.') % replace commas with full stops
fileid = fopen('yourfile.txt','w') % open file to write
fprintf(fileid,'%s',newfiledata) % print to file
fclose(fid2)
別のオプション(ファイルをmatlabのワークスペースで開きたいため)は次のとおりです。
を使用してファイルをロードします
a=load('filename.txt');
カンマはデフォルトの区切り文字であるため、次のような2xNマトリックスを取得します。
a =
0 472412
0 455627
0 439148
0 421753
適切な小数点位置を取得するには、有効な桁数を見つけます。
d = 10.^(1+floor(log10(abs(a(:,2)))));
それから:
v=a(:,2)./d
必要なベクトルが生成されます。これで、ファイルに保存するか、何でもできます...
a='0,00445'
= 0,00445
b=strrep(a,',','.')
b = 0.00445