Use of TreatAsEmpty to replace table values

조회 수: 23 (최근 30일)
Dionisio Mendoza
Dionisio Mendoza 2021년 8월 23일
댓글: dpb 2021년 8월 30일
Hello, im trying to import a .xsl doc to matlab using the next code:
data=readtable('C:\Users\Alfred\OneDrive\Libro1.XLSX','TreatAsEmpty',{''})
The file contains 3 columns with different values. The problem is that some random cells are empty so I been using 'TreatAsEmpty' to convert those empty spaces to NaN.
When I open the data, only column 3 shows with the NaN. Column 1 and 2 still have empty cells "". No matter what value or character I try to substitute, only the last column is always affected.
I'm missing something?
thanks.
  댓글 수: 2
Cris LaPierre
Cris LaPierre 2021년 8월 23일
Share you xls file. You can attach it using the paperclip icon.
Dionisio Mendoza
Dionisio Mendoza 2021년 8월 29일
Here it is.

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

채택된 답변

dpb
dpb 2021년 8월 23일
'TreatAsEmpty' Placeholder text to treat as empty value
character vector | cell array of character vectors | string | string array
Placeholder text to treat as an empty value, specified as the comma-separated pair consisting of
'TreatAsEmpty' and a character vector, cell array of character vectors, string, or string array.
Table elements corresponding to these characters are set to NaN.
'TreatAsEmpty' only applies to numeric columns in the file, and readtable does not accept
numeric literals, such as '-99'.
Undoubtedly, the other columns are nonnumeric. It's possible they're supposed to be interpreted as numeric but owing to the missing values are not discerned as such by the default data type recognition logic built into readtable. Prior to R2020b readtable did not do as exhaustive a search as detectImportOptions does.
As @ChrisR notes, it's much easier if we can see the file itself, but you may need to get more explicit with the import options object.
  댓글 수: 4
Dionisio Mendoza
Dionisio Mendoza 2021년 8월 29일
Looks nice, Thank you.
So there is no way to deleate a specific string in a table obtainig a empty cell?
dpb
dpb 2021년 8월 30일
That's what <missing> or the '0x0 char' are -- empty cells. That's MATLAB's way of displaying an empty string array element or an empty char() string.
A table view in the command window is NOT a printed report; it's a working representation of the data in memory.
Again, if it's just the visual representation you don't like, with a string array you can have an empty string...
>> s="A";
>> s(3)="B";
>> s
s =
1×3 string array
"A" <missing> "B"
>>
builds a string array w/ a missing element.
>> s(ismissing(s))=""
s =
1×3 string array
"A" "" "B"
>>
replaces any missing array elements with the empty string.
The two are NOT the same, but maybe you'll like the way one looks better than the other.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by