How to change the output file name with the same input file name but with a different extension ?

4 ビュー (過去 30 日間)
In line 1, I have read all files with .nc extension. And in the last fourth line, I want to save the output file with the same name but with different extension. For eg. If the input file name is 'BOB_LEHAR_CS_2013112718_TRMM.nc' then i want to save the output file as 'BOB_LEHAR_CS_2013112718_TRMM.grd' How to do this. Please help me.
File= dir('*.nc');
for j =1:2
dx= 10
radius= 600
lon=ncread(File(j).name,'lon');
lat=ncread(File(j).name,'lat') ;
rain=ncread(File(j).name,'rf');
rain=rain(:,:,1);
for i =1: radius/dx
i=i*dx
A=cyclonic(0,0,1,i,lat,lon,rain);
B(:,i/dx)=A(:,4);
end
B1=B(1:360,:);
fpo=fopen(sprintf('file%i.grd',j),'wb');
fwrite(fpo,B1,'float32');
fclose(fpo);
end

採用された回答

Stephen23
Stephen23 2017 年 9 月 6 日
編集済み: Stephen23 2017 年 9 月 6 日
Use fileparts to get the filename without the extension:
>> old = 'BOB_LEHAR_CS_2013112718_TRMM.nc';
>> [~,name] = fileparts(old);
>> new = sprintf('%s.grd',name)
new = BOB_LEHAR_CS_2013112718_TRMM.grd

その他の回答 (1 件)

José-Luis
José-Luis 2017 年 9 月 6 日
old = 'BOB_LEHAR_CS_2013112718_TRMM.nc';
new = regexprep(old, '\.[^.]+$', '.grd')

カテゴリ

Help Center および File ExchangeWeather and Atmospheric Science についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by