1

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_try=['D:\lst2016\lst_try\modis',num2str(i),'.hdf'];

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

end

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

save(lst_try,'lst_3','-hdf')

But not able to save file individually.

1 Answers1

1

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

partname='myfile'

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','-ascii') %saving by separated names

end

Note that i used '-ascii' option, as the save function does not takes the hdf format. This comes with a drawback, you can save only matrix of size (N,M).

The ascii option cannot take 3D data.

Guto
  • 541
  • 5
  • 14
  • The problem is rather that he saves all data in one variable and tries to save this at once "individually" – Irreducible Oct 11 '17 at 10:31
  • @Irreducible Indeed. I was imagining that the analysis was done inside the same loop. I will make a correction indeed. – Guto Oct 11 '17 at 10:33
  • @Guto Thanks for helping, but matlab is showing this error:myfile Error using save Unknown command option. Error in stackoverflow (line 15) save(name,'var_temp','-hdf') %saving by separated names – Vaishali Jain Oct 12 '17 at 06:48
  • @VaishaliJain `-hdf` is indeed not a format recognized on `save`. You could use [`imwrite`](https://se.mathworks.com/help/matlab/ref/imwrite.html). There is [this](https://se.mathworks.com/help/matlab/import_export/exporting-to-hierarchical-data-format-hdf4-files.html) also. The last seems more like your case. – Guto Oct 12 '17 at 09:39
  • @VaishaliJain I can take a look, but if the problem turns into a save in hdf4 problem, i cannot help much, beyond have experience reading Matlab Manuals :P . HDF5 have a `hdf5write` function. If we got stuck in the saving hdf format, it's better to ask a new question specifically about that. – Guto Oct 12 '17 at 09:57
  • okay, can we save the files in simple matrix only? hdf format is not needed in the output files. – Vaishali Jain Oct 12 '17 at 10:21
  • @VaishaliJain I updated the question! :D, check if it fits your case. – Guto Oct 12 '17 at 10:47
  • @Guto this error is coming, Warning: Attempt to write an unsupported data type to an ASCII file. Variable 'var_temp' not written to file. My input file is in hdf format and output file is 5D matrix – Vaishali Jain Oct 13 '17 at 07:09
  • @VaishaliJain well, a 5D matrix is not supported as I wrote. Go with .mat or find a more suitable format for you. The procedure is the same. With .mat you can save even the whole environment with no need to split up names. – Guto Oct 13 '17 at 08:47
  • Okay. Thanks for the help. – Vaishali Jain Oct 14 '17 at 06:01