How can I output only part of a array?
7 ビュー (過去 30 日間)
表示 古いコメント
I wrote a code that plots a function for me. In the code, an array is given the name of the selected file. Example: FileName = 'Evaluation_114_1688.xlsm'
I would now like to save the figure as a jpg, which is why I used the command: saveas(gcf,FileName,'jpg')
But I would like to use only the numbers from the file name: 114_1688.jpg
How is it possible for me to select only the numbers from the file name?
0 件のコメント
回答 (2 件)
Voss
2022 年 7 月 3 日
This may work for you:
FileName = 'Evaluation_114_1688.xlsm';
new_name = regexp(FileName, '_([\d_]+\.)', 'tokens', 'once');
% ^ leading underscore
% ^^^^^^ followed by one or more (+) digit (\d == 0-9) or underscore (_) characters
% ^^ followed by a period
% ^ ^ group everything after the leading underscore, up to and including the period, in a "token" to be returned
new_name = [new_name{1} 'jpg']
0 件のコメント
参考
カテゴリ
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!