Auto-naming a variable based on imported file name
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi everyone,
I'm writing a code where I need to import data from specific cells in an excel file each time I want to run the code. I have to create a table of this specified data, but don't want to hard code the range of the excel file each time since the column I am pulling from is always different. I'm wondering if there is a way to automatically name the table, based on the name of the file that I import. The line of code I am currently using is
table = CalendarS4.StartTime25;
where it outputs a table of strings from the selected cells of the excel sheet. The data will always be from CalendarS4.StartTime, but the number following 'StartTime' is different based on the column I am importing data from. Is there a way to automatically name the table after the file name, without having to change the column number at the end each time? I am trying to run the program without having to change the code to match the file name.
Thanks in advance!
댓글 수: 0
답변 (1개)
Steven Lord
2021년 6월 23일
Can you do this? Sometimes. File names are not required to be valid MATLAB identifiers. I can have a file named "3 blind mice.txt" but that violates two of the rules for valid MATLAB identifiers given in the documentation for the isvarname function.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!