extracting the last three characters from cell array

36 ビュー (過去 30 日間)
sermet OGUTCU
sermet OGUTCU 2021 年 7 月 17 日
回答済み: Rik 2021 年 7 月 17 日
[FileName,pathname,d] = uigetfile('*.SP3','Choose the products','MultiSelect','on');
FileName =
1×2 cell array
{'COD0MGXFIN_20210870000_01D_05M_ORB.SP3'} {'COD0MGXFIN_20210880000_01D_05M_ORB.SP3'}
When FileName consists of single file, I extract the last three characters of FileName as follows:
FileName(end-2:end)
When FileName consists of multiple files (as shown above), how can I extract the last three characters of FileName?

採用された回答

Simon Chan
Simon Chan 2021 年 7 月 17 日
Use cellfun to retrieve the last three charaters
FileNameinCell=cellfun(@(x) x(end-2:end), FileName, 'UniformOutput', false)
FileNameinCell =
{'SP3'} {'SP3'}
FileNameinCell{1} , FileNameinCell{2}, etc =
'SP3'

その他の回答 (1 件)

Rik
Rik 2021 年 7 月 17 日
You probably want to extract the extension, instead of hard-coding the last three characters:
data={'COD0MGXFIN_20210870000_01D_05M_ORB.SP3','COD0MGXFIN_20210880000_01D_05M_ORB.SP3'};
[~,~,ext]=cellfun(@fileparts,data,'UniformOutput',false);
YouWant=strrep(ext,'.','')
YouWant = 1×2 cell array
{'SP3'} {'SP3'}

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by