avoid replacing numbers with nans when importing data from dat file

조회 수: 2 (최근 30일)
Abdulkarim Almukdad
Abdulkarim Almukdad 2020년 10월 21일
댓글: Abdulkarim Almukdad 2020년 10월 21일
I have a dat file that is mixed up with text and numbers. However, I only need the numbers from certian row to certian row (all the text and other numbers are not needed)
I have tried to use readtable function, but all the numbers I want to read are appearing as NaN. Moreover, when I convert the whole file to excel and deleted everything except my numbers then readed the file as xlsx it works but some variables appear in the following format ('123') thus matlab assume these are cells and an error appear saying that var1 and variablr 22 are double and array.
Therefore, how can I read directly from the dat file and avoid the issue of NaNs then avoid the cells and read the numbers or better to change the cell to regular double data that can be assigned to variables without errors.
  댓글 수: 6
Ameer Hamza
Ameer Hamza 2020년 10월 21일
편집: Ameer Hamza 2020년 10월 21일
When I import the file in R2020b, all columns are read correctly except column 22. You can read it as string
opts = detectImportOptions('data.csv');
opts.VariableTypes{22} = 'string';
T = readtable('data.csv', opts)
Abdulkarim Almukdad
Abdulkarim Almukdad 2020년 10월 21일
it worked maybe because I have deleted the text, I have attached a new file that includes some of the text in the data

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by