Help parsing

I am trying to work with a huge collection of files I saved from LabView. They are all saved wit hthe same filename format of: Sample_value1_value2_value3_value4
They are all binary files that I use fopen/fread to use. There is no clear extention either as the last value is a decimal and it is saved awkwardly through the Labview. The values are non-sequential as they come from various device readouts.
Is there a way to write a function that can separate the filenames so I can just call on the values I want? Or a simple way to parse out the the names so I can use one of the values to reference the whole string?

3 Commenti

bym
bym il 23 Giu 2011
I suppose changing the Labview vi to save the files in a more user friendly way is not an option?
Walter Roberson
Walter Roberson il 23 Giu 2011
Please do not create duplicate questions.
Walter Roberson
Walter Roberson il 23 Giu 2011
duplicate is at http://www.mathworks.com/matlabcentral/answers/9897-filename-parsing

Accedi per commentare.

Risposte (1)

Jan
Jan il 23 Giu 2011

1 voto

D = dir(fullfile('C:\Temp\', 'Sample_*'));
Name = {D.name};
nFile = numel(Name);
index = zeros(4, nFile);
for iFile = 1:nFile
index(:, iFile) = sscanf(Name{iFile}, 'Sample_%d_%d_%d_%d');
end
Now you can get the files which have a specific index in a specific position:
pos = 3;
value = 7;
list = Name(index(pos, :) == value);

Richiesto:

il 22 Giu 2011

Community Treasure Hunt

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

Start Hunting!

Translated by