How can I create a list or a vector with the original file name beside the corresponding number?
I converted the names of 12000 different .TXT files into a se开发者_StackOverflow中文版quence of numbers from 1 to 12000. Using Matlab, how can I create a list or a vector with the original file name beside the corresponding number?
You may want to create a cell array, since they can store both numbers and text at the same time. How you create the array depends on how you have stored the file names.
namesAndNumbers = cell(12000,2); % create cell array
%# fill in names
%# assuming the 12000 file names are in a structure you got via dir
[namesAndNumbers{:,1}] = deal(nameStruct(idxOfFirstFile:idxOfLastFile).name);
%# assuming the 12000 file names are in a cell array already
namesAndNumbers(:,1) = nameCell;
%# and for the numbers
%# assuming that the numbers are generated by a function name2number
namesAndNumbers(:,2) = cellfun(@(n)(name2number(n)),namesAndNumbers(:,1));
精彩评论