matlab截取字符串

刚想截取一个matlab字符串中间的一段字符,网上搜了一下,发现strfind这个函数是matlab用来查找字符串中的字符的。

help strfind得到的结果:

strfind Find one string within another.
K = strfind(TEXT,PATTERN) returns the starting indices of any 
occurrences of the string PATTERN in the string TEXT.返回在这个字符串中所有出现过的位置
 
strfind will always return [] if PATTERN is longer than TEXT.如果没有目标字符串则返回空矩阵
 
Examples
    s = 'How much wood would a woodchuck chuck?';
    strfind(s,'a')    returns  21
    strfind('a',s)    returns  []
    strfind(s,'wood') returns  [10 23]
    strfind(s,'Wood') returns  []
    strfind(s,' ')    returns  [4 9 14 20 22 32]

看它的例子发现这个函数很简单,我把我的例子也贴出来:

clear all; close all; clc;
HOGpath='D:\mycode\graduation_project_0403\occlusion\Cir\DATA_list_Circle_hog_data.txt';
indfir=max(strfind(HOGpath,'\'));
indlas=strfind(HOGpath,'.');
xlyb=HOGpath(indfir+1:indlas-1);
截取了最后一个‘\’和‘.’之间的字符串。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值