Why is ReadTable Deleting Data with NaN?

조회 수: 33 (최근 30일)
Alan Lee
Alan Lee 2022년 8월 12일
댓글: Alan Lee 2022년 8월 12일
I'm trying to automate the reading of several hundred excel files with identical layouts using a for loop and readtable.
Does anyone know why readtable is removing data in only SOME of my columns and replacing them with NaN? I'm a bit of an amateur, so I would appreciate any help.
Excel Spreadsheet
Matlab Line
teeth = readtable(file,'Sheet','Teeth Form Sheet','Range',''); %This reads the excel file and a particular sheet and should import all the data
Table Output
  댓글 수: 2
Cris LaPierre
Cris LaPierre 2022년 8월 12일
Please attach your file using the paperclip icon.
Alan Lee
Alan Lee 2022년 8월 12일
Sorry to waste your time Cris.

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

채택된 답변

Alan Lee
Alan Lee 2022년 8월 12일
I figured it out. The issue was that not all my data points were the same Data type and that Readtable was getting confused. Once I converted all the data to Characters there were no more issues,
opts = detectImportOptions(file,'Sheet','Teeth Form Sheet','Range','');
opts = setvartype(opts,'char');
teeth = readtable(file,opts);

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2022년 8월 12일
The columns of a table must all be of the same datatype. readtable has set the datatype for each column based on the datatype in the first row. When the datatype is set to numeric and non-numeric information is encountered, it is replaced with NaN, meaning "not a number".
It looks to me like the data you want to read in is actually in rows 2-4 and 7-9. You can use the import tool to interactive create your import, or the options field of readtable.
  댓글 수: 1
Alan Lee
Alan Lee 2022년 8월 12일
Spot on Cris. I didn't think to look at that until I'd already uploaded.

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

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by