相关文章推荐
小眼睛的莲藕  ·  Python strip()方法 - ...·  3 周前    · 
大力的勺子  ·  python ...·  3 周前    · 
豪气的移动电源  ·  mysql ...·  2 周前    · 
小胡子的木瓜  ·  javascript - ...·  2 年前    · 
耍酷的木瓜  ·  Android ...·  2 年前    · 
save_path = 'H:\Experiment\Img\';
smap_list = 'P1_front_img.jpg';
cell_str = strsplit(smap_list,'_');  %分成三段: 'P1'    'front'    'img.jpg'
smap_name = cell_str{1,1};
save_full_path = strcat(save_path, smap_name, '.jpg');  % H:\Experiment\Img\P1.jpg

灵活使用strsplit函数,可以截取任意位置的字符串。

二,利用索引,功能简单直接

因为字符串索引是从1开始,最后的索引是end,这里举个栗子:字符串是000_HC_Annotation.png,目的是去掉后面的_Annotation.png,具体实现如下。

img_name = '000_HC_Annotation.png'; # 000_HC_Annotation.png
new_name = img_name(1:end-15); # 这样就去掉了_Annotation.png字符串,新的名字:000_HC
这里介绍两种方法,各有优点一,strsplit函数,功能强大save_path = 'H:\Experiment\Img\';smap_list = 'P1_front_img.jpg';cell_str = strsplit(smap_list,'_'); %分成三段:'P1' 'front' 'img.jpg'smap_name = cell_str{1,1...
matlab 中取 字符串 数组中某个 字符串 的某个字符 做课程作业时候脑子当机了,死活不知道怎么取来着,百度也找不到,然后瞎试试,居然试出来了,我得记一下,万一下次用得到。 matlab A={'000' '001' '100'}; A{1,1}(1); %最后结果取出来的是第一个 字符串 中的第一个字符‘0’ C = strsplit(str,delimiter) C = strsplit(str,delimiter,Name,Value) [C,matches] = strsplit(___) C = strsplit(str) 在空白处将 str 拆分为 C。空白字符等效于集合 {’ ‘,’\f’,’\n’,’\r’,’\t’,’\
str = 'Find the starting indices of substrings in a character vector'; k = strfind(str,'in') k = 1×5 2 15 19 36 41 拆解文件名(除去后缀) str = filename; pat = '_'; newStr = extractBefore(str,pat);
仅作为学习记录,大佬请跳过。 bluetoothread='#-0.115000*-0.205000##-0.115000*-0.175000##-0.115000*-0.155000#; 博主提取字符’#‘和’‘之间的数据 【注意,提取的不包括‘和‘#’之间的数据】 1、extractBetween——(extractBetween得到的是cell型数据) 2、cell2mat——c...