empty output when indexing excel file

조회 수: 2 (최근 30일)
avram alter
avram alter 2019년 12월 11일
댓글: Walter Roberson 2019년 12월 12일
I have an excel file that has the dates in column A. other columns are filled with info pertaining to that day. I want to be able to find a row number using todays date. here is the code:
addpath('C:\Users\Administrator\Dropbox (********)\******** Team Folder\Matlab\RFID chip reader');
[~,~, found] = xlsread('example_Update.xlsx');
p = strcmp(date, found(:,:));% Compare user input string with entries in the Excel sheet
rowNum = find(p==1)%Get Row number
this is supposed to open an excel file, look for todays date, and return the number of the row. however, this is my output:
rowNum =
0×1 empty double column vector
I am not sure why this is happening. I appreciate any help

채택된 답변

Walter Roberson
Walter Roberson 2019년 12월 11일
When you use the raw output of xlsread(), the values for dates are not in character format: they are in Excel numeric format, which is typically number of days since Jan 1, 1900 (but with a leap year bug for 1900 itself.)
datetime(cell2mat(found(2:end,1)),'convertfrom','excel')
I would suggest that you should consider switching from xlsread() to use readtable()
  댓글 수: 2
avram alter
avram alter 2019년 12월 12일
This is even if I wrote into Excel the same format as matlab's date format? Ie 11-Dec-2019
Walter Roberson
Walter Roberson 2019년 12월 12일
Excel does not store dates as character vectors even when you type in character vectors: it stores dates in numeric form.
If I remember correctly, if you are using MS Windows with Excel installed, then when you use xlsread() text output (second output) you will get the date in character vector form, but the raw output (third output) will be in the original numeric form.
readtable() detects excel dates and converts them to datetime objects. readtable() is not always able to detect hours and minutes stored in a seperate field and convert those automatically: it often does, but it depends exactly how the values were stored in Excel.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by