How to save each file in a for loop using matlab

I have three files named as modis1.hdf, modis2.hdf and modis3.hdf in one folder. I am able to read files individually using my command.

for i=1:3 or for i=1


lst_3(:,:,:,:,i)=hdfread(lst_try, 'MODIS_Grid_Daily_1km_LST', 'Fields', 'LST_Day_1km', 'Box',{[76.83        77.34], [28.88        28.41]});


I want to save each file separately either in hdf format or ascii format. Therefore, i was using command


But not able to save file individually.

1 answer

  • answered 2017-10-11 10:29 Guto

    Just make individual names for every savefile.

    If i understood right, you are having different data separated in a matrix dimension. Just separated these data and save it individually.

    %do whatever you need to do
    for ii=1:3,
      var_temp=lst_3(:,:,:,:,ii); %split the interesting part of you data. 
      name=[partname num2str(ii)]; %make a individual name
      save(name,'var_temp','-hdf') %saving by separated names