print last three chars of filename

42 ビュー (過去 30 日間)
Gmc
Gmc 2015 年 1 月 26 日
コメント済み: Gmc 2015 年 1 月 27 日
Hello - I have a list of filenames which always end with the authors' initials preceding the extension (e.g., GM_video_9_HLL.TXT). I need to read in just the initials like this
output = dir('*.TXT');
for k = 1:numel(output)
initials = (output(k).name(19:21));
end
fid = fopen('fields_test1.txt','wt');
fprintf(fid,'OPEN\n');
fprintf(fid,'------------\n');
fprintf(fid,'Field(' , initials , ')\n');
fclose(fid);
The problem is the last three letters are not always at space 19:21 as in the example but they are always the last three letters before the extension in the filenames. Any help would be very much appreciated!
Thank you

採用された回答

Steven
Steven 2015 年 1 月 26 日
filename(end-3:end)

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 1 月 26 日
initials = output(k).name(end-6:end-4);
  1 件のコメント
Gmc
Gmc 2015 年 1 月 27 日
Thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by