MATLAB Answers

empty output when indexing excel file

조회 수: 4(최근 30일)
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

  댓글 수: 0

로그인 to comment.

채택된 답변

Walter Roberson
Walter Roberson 11 Dec 2019
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.)
I would suggest that you should consider switching from xlsread() to use readtable()

  댓글 수: 2

avram alter
avram alter 12 Dec 2019
This is even if I wrote into Excel the same format as matlab's date format? Ie 11-Dec-2019
Walter Roberson
Walter Roberson 12 Dec 2019
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.

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.





Translated by