Extract part of filepath and using like legendname
17 次查看(过去 30 天)
显示 更早的评论
Hello,
I have paths like this:
FilePath = '/home/user/workspace/QT/Software_2.0_QT/IO/Motor_Set_1/AKG_C1000S/Distance_0.5m/Scenario_M1/001_m1_60_const_20200611_200515/SNR_F1/'
and I need to save (in a loop)
Save_path{k} = 'Motor_Set_1/AKG_C1000S/Distance_0.5m/Scenario_M1/001_m1_60_const_20200611_200515/'
or maybe I can set it also shorter (for a plot legend)!?
Save_path{k} = 'MS1/AKG/0.5m/M1/001/'
?
Variables are:
Motor_Set_1, Motor_Set_2, Motor_Set_3
AKG_C1000S, SONY_D50
Distance_0.5m, Distance_2m
Scenario_M1, Scenario_M2, Scenario_M4
001_m1_..., 002_m1_m2..., ..., 030_m4_m3...
How can I cut it?
Thank you!
0 个评论
采纳的回答
Adam Danz
2020-6-24
编辑:Adam Danz
2020-6-25
Make sure all slashes are forward shashes
FilePath = strrep(FilePath, '\','/');
Replace any double shashes with single slashes
strrep(FilePath, '//','/')
Find the position of the slashes
slashIdx = strfind(FilePath, '/');
Choose which segments of the path you want to extract (here I chose segment 10 to 13)
pathSegment = FilePath(slashIdx(10)+1:slashIdx(13)-1)
The +1 and -1 remove the slash from the beginning and end of the segment.
You could also use regular expressions or some of the other string search functions if you want to search for a specific starting and ending directory.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!