필터 지우기
필터 지우기

Find empty cells in excel

조회 수: 28 (최근 30일)
John Rebbner
John Rebbner 2018년 11월 14일
답변: Surendra Reddy Kovvuri 2021년 3월 26일
Hi! I am trying to read data from a specific column in excel, but want to stop my code when it meets an empty
Here is my code:
[~,~,raw] = xlsread('file_name');
if isempty(raw(6,1)) == 1
disp('empty')
else
disp('non-epmty')
end
And evry time the code displays 'non-empty' even though the cell raw(6,1) is filled.
Any suggestions why ???
  댓글 수: 1
Stephen23
Stephen23 2018년 11월 14일
Note that putting
== 1
does nothing. Get rid of it.

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

답변 (3개)

Stephen23
Stephen23 2018년 11월 14일
편집: Stephen23 2018년 11월 14일
You used the wrong kind of indexing. You need to use curly braces:
isempty(raw{6,1})
^ ^
The difference is simple:
  • () parentheses access the cells themselves.
  • {} curly braces access the cell contents (which is what you want to check).
Read more:
  댓글 수: 2
John Rebbner
John Rebbner 2018년 11월 14일
Thank you! I've changed the code as you show me, but it seems as there is no difference because I change raw{6,1} which is a filled cell and for instance raw{10,1} is empty and the answer is 0 every time.
Stephen23
Stephen23 2018년 11월 14일
@John Rebbner: If the cell is not empty then you should check the actual content of that cell. It might contain an empty string or something else the Ecxel something puts in cells. If you upoad your file then someone can help you with that.

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


Guillaume
Guillaume 2018년 11월 14일
Have you checked what the content of raw actually is for cells that are empty in excel? In my version of matlab (2018b) with my version of excel (office 365), an empty excel cell is translated to NaN not an empty array in matlab, so testing for emptiness is not going to succeed. Testing for NaN would have more success (with isnan)

Surendra Reddy Kovvuri
Surendra Reddy Kovvuri 2021년 3월 26일
Please try this below condition
~isempty(find(isnan(raw{6,1})))
Thank you

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by