简体   繁体   English

使用matlab / octave将目录文件部分拆分为多个部分

[英]splitting directory fileparts into sections using matlab / octave

I would like to split pathstr into separate parts how can I do this? 我想将pathstr拆分为单独的部分,该怎么做? See example below. 请参见下面的示例。

PS: I'm using octave 3.8.1 PS:我正在使用八度3.8.1

dpath='tmp/h1/cli/pls/03sox_a_Fs_1000/'
[pathstr,name,ext] = fileparts(dpath)

>>>pathstr = tmp/h1/cli/pls/03sox_a_Fs_1000

If all I want is 03sox_a_Fs_1000 or pls How can I do this? 如果所有我想要的是03sox_a_Fs_1000我怎样才能做到这一点?

Please note the filenames will change and could be of different lengths. 请注意,文件名将更改,并且文件名可以不同。

You can use strsplit (here using Matlab) to split your string (believe it or not!) using the delimiter / : 您可以使用strsplit (此处使用Matlab)通过定界符/来分割字符串(信不信由你!)。

pathstr = 'tmp/h1/cli/pls/03sox_a_Fs_1000'

[Name,~] = strsplit(pathstr,'/')

Now Name looks like this: 现在Name看起来像这样:

Name = 

    'tmp'    'h1'    'cli'    'pls'    '03sox_a_Fs_1000'

So you can select the last element using the end keyword and curly braces since the output of strsplit is a cell array: 因此,由于strsplit的输出是一个单元格数组,因此可以使用end关键字和花括号来选择最后一个元素:

Name = Name{end}

or end-1 to retrieve pls . end-1以获取pls

This applies to names of any length or format, as long as they are separated by / . 只要以/分隔,这适用于任何长度或格式的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM