Hi, I'm trying to import the .dat file attached in Matlab but I have a problem. I'm using the following command: fid=fopen('doe.dat','rt'); A= fscanf(fid, '%f'); fclose(fid);
but A is just equal to 9 insted of the two columns of number.
How I can load the two columns as a matrix?
Thanks Alessandra

 採用された回答

Mostafa
Mostafa 2016 年 10 月 12 日

0 投票

Try this:
A = textscan(fid, '%s', 'Delimiter', ' ');
impData = A{1}; %%This cell contains your data
impData = impData (3:end); %%The data excluding the first two lines
strData = cellfun(@strsplit, impData, 'UniformOutput',0); %%Split data into two rows
numData = cellfun(@str2double, strData, 'UniformOutput',0); %%Convert to numeric values
matData = cell2mat(numData); %%Convert into a matrix

3 件のコメント

Alessandra Cuneo
Alessandra Cuneo 2016 年 10 月 12 日
I've just tried to do it but the impData is a array of 161x1 with a lot of empty cell. So in the matData the empty cell become NaN. However the data are not split in to columns but matData remain a array of 161x1
Mostafa
Mostafa 2016 年 10 月 13 日
Can you upload the actual .dat file? I only considered the data in the picture as inupt.
Mostafa
Mostafa 2016 年 10 月 13 日
You can add this line to remove the empty cells before splitting it into rows.
impData(cell2mat(cellfun(@isempty,impData,'UniformOutput',0))) = [];

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2016 年 10 月 12 日

コメント済み:

2016 年 10 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by