Load .mat file

조회 수: 2 (최근 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에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by