Formatting exel import in readtable()

조회 수: 4 (최근 30일)
Akshayaa Pandiyan
Akshayaa Pandiyan 2022년 10월 3일
댓글: Star Strider 2022년 10월 6일
I have an excel file with char arrays and numerical data. I import the data using readtable(). I want all the data to be homogeneous, that is either all or none of them as cell array. Currently i import the table and search through the table and change the type using num2cell(). Is there a better way to import all the columns as cell arrays irrelavent of whether they are a string/double?
Edit: Attached is the file I want to load into matlab. I have columns of string and numbers(or num arrays). But it could be that some columns can be completely empty. If the entire column is empty, readtable reads the missing values as NaN (type: double). If one or more values is present in a column, then readtable read the missing values as {'0x0 char'}. I wanted to remove this ambiguity.

채택된 답변

Star Strider
Star Strider 2022년 10월 3일
It would help to have the Excel file to experiment with.
In its absence see the documentation on detectImportOptions and experiment with it.
  댓글 수: 2
Akshayaa Pandiyan
Akshayaa Pandiyan 2022년 10월 6일
Thanks Star, I looked into it and this worked
opts = detectImportOptions(fileName);
opts = setvartype(opts, 'char');
opts = setvaropts(opts, 'FillValue', '');
Star Strider
Star Strider 2022년 10월 6일
As always, my pleasure!
An interesting solution!
I did not see the Excel file until just now. It seems as though you solved the problem, however if you need more help with it I will do what I can.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by