How to open a file in MATLAB, which has comma as decimal separator.

6 ビュー (過去 30 日間)
Jesus
Jesus 2013 年 10 月 15 日
コメント済み: Jesus 2013 年 10 月 20 日
How to open a file (.txt or.dat), which has comma as decimal separator. My file has two columns (the first column is using comma as decimal separator). The two columns of the file are separated by space. My file looks like this:
1,94534 228
1,94534 231
1,97364 228
1,97364 231
2,00235 228
2,00235 231
2,00235 234
2,03148 228
2,03148 231
2,03148 234
2,06103 231
2,06103 234
2,09101 228
2,09101 231

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 15 日
編集済み: Azzi Abdelmalek 2013 年 10 月 15 日
Edit
fid=fopen('file.txt')
s=textscan(fid,'%s %s')
fclose(fid)
v1=str2double(strrep(s{1},',','.'))
v2=str2double(s{2})
  2 件のコメント
Jesus
Jesus 2013 年 10 月 15 日
編集済み: Jesus 2013 年 10 月 15 日
Azzi Abdelmalek, thanks for the reply. Your answer worked perfectly.
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 15 日
Look at edit

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

その他の回答 (1 件)

Jan
Jan 2013 年 10 月 16 日
S = fileread('file.txt');
S = strrep(S, ',', '.');
D = sscanf(S, '%g', [2, inf]);
  1 件のコメント
Jesus
Jesus 2013 年 10 月 20 日
Jan Simon, thanks for the reply.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by