필터 지우기
필터 지우기

How do I test a variable to see if it is empty?

조회 수: 15 (최근 30일)
Eric Metzger
Eric Metzger 2021년 10월 17일
댓글: Eric Metzger 2021년 10월 17일
I have a data file that I read in using readtable. It reads the file fine but is has a number columns which come up empty and readtable will just make it a simple empty cell. This is not a hugh deal but I need to find a way to test if the cell is actually empty and if so, to put a value in its place which is based on what was done previously. I have done this before and have a fast process to make this happen, just can't seem to figure out how to deal with the empty value cell.
Is there a simple test or check I an use in MatLab that will return a value that can be used in an "if" statement?
Here is a small sample of the readtable results. It comes from a very large .xlsx file so it is not feasable to alter the value in the source file
'5628' '9/30/2021 7:28:56 AM' '' '38' '' '' ''
'5629' '9/30/2021 7:29:02 AM' '64.652' '' '' '' ''
'5630' '9/30/2021 7:29:11 AM' '' '39' '' '' ''
'5631' '9/30/2021 7:29:27 AM' '' '40' '' '' ''
'5632' '9/30/2021 7:29:42 AM' '' '41' '' '' ''
'5633' '9/30/2021 7:29:57 AM' '' '42' '' '' ''
'5634' '9/30/2021 7:30:02 AM' '64.481' '' '' '' ''
'5635' '9/30/2021 7:30:12 AM' '' '43' '' '' ''
'5636' '9/30/2021 7:30:28 AM' '' '44' '' '' ''
'5637' '9/30/2021 7:30:46 AM' '' '45' '' '' ''
'5638' '9/30/2021 7:31:02 AM' '64.31' '' '' '' ''
'5639' '9/30/2021 7:31:07 AM' '' '46' '' '' ''
The first colume is the event line or number or recorded events
Second column is obvious
The thrid and fourth columns are the tricky part. These are the values recorded at the event time. Note the " is in place of a NaN or zero. Readtable puts this in an empty cell which I need a way to quickly test if it is empty and then do something based on previous information ingested.
Any thoughts?

채택된 답변

Walter Roberson
Walter Roberson 2021년 10월 17일
Use detectImportOptions() on the file, and use setvartype() to force the columns to be double, and then readtable.
When you do that, empty entries will come up as NaN. You can then use fillmissing() which has a specific option to use the most recent non-nan value.
  댓글 수: 1
Eric Metzger
Eric Metzger 2021년 10월 17일
Thank for the options. I have not used this before so I will have to fiddle with them so be sure I use them right. Will post again if I have questions.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by