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 Center および File ExchangeSpreadsheets についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by