gpt4 book ai didi

Matlab查找名称中包含文本的所有文件

转载 作者:行者123 更新时间:2023-12-02 07:33:50 24 4
gpt4 key购买 nike

在我的目录中有两种命名文件的模式。

模式一:

'XXXXXX FixedCost_zz123.mat'

模式二

'XXXXXX FixedVolume.mat'

因此,基于上面我文件夹中真实文件的一些示例是:

'Sap FixedCost_pkz123.mat'
'ASDFG FixedCost_z1.mat'
'TUP112RA FixedCost_h1453.mat'
'as FixedVolume.mat'
'P1234L FixedVolume.mat'
'afg FixedVolume.mat'

我希望能够在任何情况下根据我的需要找到“FixedCost”和“FixedVolume”类型的所有文件。我如何实现这一目标?我对该函数的输入是“FixedCost”或“FixedVolume”。

最佳答案

您可以使用带有指定文件名模式的参数的 dir 函数:

fixedCostFiles = dir('*FixedCost*.mat');
fixedVolumeFiles = dir('*FixedVolume.mat');

如果您想要更复杂的选择并且不怕 java,您还可以使用 apache FileUtils,它们是 MATLAB java 的一部分:

http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html

具体来说,检查 listFiles 函数。

关于Matlab查找名称中包含文本的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18923744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com