reading files that contain changing parts and parts that need to be ignored
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Luis Eduardo Cofré Lizama
el 16 de Sept. de 2022
Comentada: Luis Eduardo Cofré Lizama
el 18 de Sept. de 2022
Hi there I am trying to read in a loop a series of files that have certain parts that need to be ignored and others vary. For example I want to read the file 'h001s1_EC1_Sway.h5' for which I did the following considering the varying parts of the file:
read(strcat(saveres,'***',num2str(r),'_s',num2str(s),'_',cond,num2str(t),'_****.h5'));
but didnt work.
Any ideas how can I do it so I ignore the '*' parts when reading the file?
Many thanks
0 comentarios
Respuesta aceptada
Rik
el 16 de Sept. de 2022
You need to use dir to find the actual file name matching some pattern. Then you can provide the function with the real file name. Unless explicitly stated otherwise, Matlab functions do not allow you to provide a file pattern instead of a real name.
4 comentarios
Rik
el 16 de Sept. de 2022
Did you read the documentation for the dir function? I suspect you didn't. A wildcard in the context of dir can replace multiple characters, so just 1 asterisk will suffice. You also need to provide a single char array.
Something like this should do.
ListOfFiles = =dir(strcat(...
saveres,'*',num2str(r),'_s',num2str(s),'_',cond,num2str(t),'_*.h5' ));
That will return a struct with file details. If you're lucky there will only be 1 match and you can use this to extract the file name:
filename = ListOfFiles.name;
If there are multiple matches, you need to loop through the result to find the one you need. The regexp function may be helpful in that case.
Más respuestas (0)
Ver también
Categorías
Más información sobre File Operations 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!