MATLAB: Load .mat file

.dat fileloadmatrix

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

Best Answer

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
Related Question