4

私はこの列のようなテキストファイルを持っています:

0,472412
0,455627
0,439148
0,421753
...
0,116577
0,086670
0,057373
0,027161

matlabでコンマをドットに変換するにはどうすればよいですか?

4

4 に答える 4

4

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 
于 2012-10-30T15:53:04.323 に答える
2

...またはこれを行うことができます:

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)
于 2012-10-30T17:11:13.303 に答える
1

別のオプション(ファイルを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
    

必要なベクトルが生成されます。これで、ファイルに保存するか、何でもできます...

于 2012-10-30T16:13:10.983 に答える
1

a='0,00445'

= 0,00445

b=strrep(a,',','.')

b = 0.00445

于 2014-07-24T08:16:05.237 に答える