Problem with identification of strings

1 visualizzazione (ultimi 30 giorni)
ludvikjahn
ludvikjahn il 25 Feb 2015
Modificato: Guillaume il 25 Feb 2015
Good Mornig,
could you find a solution for this: if I input:
files = dir(fullfile(open_folder, '*140821*.txt'));
it finds a structure array, anyway, if I try with:
b=strcat('*','140821','*')
files = dir(fullfile(open_folder, 'b.txt'));
It doesn't find any.
I would like to name a 'b' and than find the related file in the directory but that doesn't seem the right way!!
Could you help me?

Risposta accettata

Guillaume
Guillaume il 25 Feb 2015
Modificato: Guillaume il 25 Feb 2015
files = dir(fullfile(open_folder, [b '.txt']));
or
files = dir(fullfile(open_folder, strcat(b, '.txt')));
or
files = dir(fullfile(open_folder, sprintf('%s.txt', b)));
The last one is my personal preference, and I would build b the same way:
b = sprintf('*%d*', 140821);
Note that in 'b.txt' the b is just the character 'b', there's no reason matlab would interpret it as the variable b.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by