strfind issue
古いコメントを表示
Hi,
I have a filename (including whole path) as a string with directories separated by / e.g. root/folder/file.
I am using strfind to find the slashes as follows and to give an index array of the position of the / symbols, :
% Find all occurances of the string '/'
[no_slash] = strfind ( line, '/' );
and then trying to extract the filename as a string as follows:
% Extract the case number:
caseNo = ( [no_slash(3)+1 : no_slash(3)+4] );
I get NaN returned and I don't know why! If anyone has an idea or an alternative method then it would be much appreciated!!
Thanks,
Robbie
採用された回答
その他の回答 (1 件)
Daniel Shub
2011 年 11 月 29 日
The only way
[no_slash(3)+1 : no_slash(3)+4]
can be equal to NaN is if no_slash(3) is equal to NaN. You are not showing us something important because I am pretty sure that strfind does not return NaN.
All that said fileparts might help you out...
doc fileparts
3 件のコメント
Robbie
2011 年 11 月 29 日
Daniel Shub
2011 年 11 月 29 日
What is no_slash equal to? Can you check that line is also a string. Please post a MWE with what line needs to be to get the error?
Robbie
2011 年 11 月 29 日
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!