empty output when indexing excel file

2 Ansichten (letzte 30 Tage)
avram alter
avram alter am 11 Dez. 2019
Kommentiert: Walter Roberson am 12 Dez. 2019
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 11 Dez. 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.)
datetime(cell2mat(found(2:end,1)),'convertfrom','excel')
I would suggest that you should consider switching from xlsread() to use readtable()
  2 Kommentare
avram alter
avram alter am 12 Dez. 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 am 12 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by