Name must be a text scalar
43 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I wan to use the datetime() function to name a folder. Moreover, I want to change the format with the replace() function and later access this folder via dir(). However, I get an error that says "Name must be a text scalar". I suppose the reason lies in the replace function. Is there any other way to do this?
actual_time = datestr(datetime('now')); % holt die aktuelle Zeit
files = dir([actual_time '\*.txt']); % works
actual_time = fullfile(replace(actual_time, ':', '-'))
files = dir([actual_time '\*.txt']); % error
2 comentarios
Stephen23
el 7 de Jun. de 2023
Editada: Stephen23
el 7 de Jun. de 2023
They both work here (I also replaced deprecated DATESTR with the recommended CHAR).
Note that you should use FULLFILE instead of concatenating text together.
actual_time = char(datetime('now'))
S1 = dir([actual_time '\*.txt']) % Should use FULLFILE here
actual_time = fullfile(replace(actual_time, ':', '-'))
S2 = dir([actual_time '\*.txt']) % Should use FULLFILE here
"Is there any other way to do this?"
Explicitly specify the DATETIME format:
DT = datetime('now','Format','uuuu-MM-dd HH-mm-ss')
S = dir(fullfile(char(DT),'*.txt'))
Respuestas (0)
Ver también
Categorías
Más información sobre Variables 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!