Importing Dates as variable names in an table from Excel
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello,
I'm trying to import data from Excel into MATLAB as a table, but I'm running into issues regarding variable labels.
The excel sheet is an automatically generated report with n rows representing various sites, and m columns. The first four columns give details of the site (location, site ID number, etc.) and then the rest of the columns represent dates from the time the tracking began to the day of the report. These columns are filled with 1s and 0s, ie 1 if I pinged that site that day and 0 if I didn't. I'd like to write this script in such a way that I can run the report and import it regardless of the date range I select for the report, so it needs to be very flexible.
Unfortunately, due to the variable difference between my pseudoboolean 1s and 0s and the date headers, when I import the data as a table, all my date columns assume a VarName5, VarName6, ...etc. variable name instead of the proper dates. This date information is important for the data manipulation I'm looking for. Does anyone know how to get the dates to come across as headers even if the variable type of the rest of each column is different?
Thanks!
Visual example of excel sheet:
Location IDNumber 3/1/2023 3/2/2023 3/3/2023 ...
LocationA ID_A 0 0 1
LocationB ID_B 1 1 1
LocationC ID_C 0 0 0
...
댓글 수: 2
답변 (1개)
Sulaymon Eshkabilov
2023년 12월 9일
Here is one option that partially solves your exercise and explains it can't be solved completely:
T_VARS = readtable('VAR_SAVE.xlsx', ReadVariableNames=true,Range='A1:D5')
댓글 수: 1
Stephen23
2023년 12월 9일
편집: Stephen23
2023년 12월 9일
"...and explains it can't be solved completely"
Reading and following the advice in the warning message:
T = readtable('VAR_SAVE.xlsx', 'ReadVariableNames',true, 'VariableNamingRule','preserve')
Note that those dates are store in the excel as Excel serial date numbers (days since 1 Jan 1900), apparently the formatting is not stored for each cell.
Also note that columns E and F contain identical headers, which READTABLE must modify to be unique.
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!