如何创建一个列表或向量,其中原始文件名位于相应的数字旁边?

发布于 2024-08-22 21:45:31 字数 91 浏览 13 评论 0原文

我将 12000 个不同的 .TXT 文件的名称转换为从 1 到 12000 的数字序列。使用 Matlab,如何创建一个列表或向量,其中原始文件名位于相应的数字旁边?

I converted the names of 12000 different .TXT files into a sequence 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵山崖 2024-08-29 21:45:31

您可能想要创建一个元胞数组,因为它们可以同时存储数字和文本。创建数组的方式取决于存储文件名的方式。

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));

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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文