Auto-naming a variable based on imported file name
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Steven Lord
el 23 de Jun. de 2021
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 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!