Load .mat file

5 次查看(过去 30 天)
Alessandra Cuneo
Alessandra Cuneo 2016-10-12
评论: Mostafa 2016-10-13
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
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 个评论
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 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by