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 个评论

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

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2011-6-23
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);

类别

帮助中心File Exchange 中查找有关 LabVIEW 的更多信息

提问:

2011-6-22

Community Treasure Hunt

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

Start Hunting!

Translated by