Matlab batch processing for HDF data gives error. If i use single operation it perfectly works. But not working in batch operation. My code is here
files = dir('/upload/server/php/files/*.hdf');
for k = 1:numel(files)
L_865 = hdfread(files(k).name, '/Geophysical Data/L_865', 'Index', {[1 1],[1 1],[6120 1243]});
L_620 = hdfread(files(k).name, '/Geophysical Data/L_620', 'Index', {[1 1],[1 1],[6120 1243]});
NDVI = (L_865- L_620) ./ (L_865 + L_620);
NDVI=NDVI-min(NDVI(:));
NDVI=NDVI./max(NDVI(:));
[J,~]=gray2ind(NDVI);
imwrite(J,jet,['/server/php/files/images/'files(k).name],'jpg');
end
Error is
Error using hdfread>dataSetInfo (line 348)
Could not open file 'OxxxST_S.hdf'.
Error in hdfread (line 209)
[hinfo,params] = dataSetInfo(varargin{:});
Error in batchndvi (line 7)
L_865 = hdfread(files(k).name, '/Geophysical Data/L_865', 'Index', {[1 1],[1 1],[6120
1243]});
You use
dirin a specific directory,/upload/server/php/files/to find your files. You also later write out to the same directory (withimwrite).However, you don't specify the directory when you use
hdfread, so it probably can't find the file. You may have previously been in the correct directory when running the code, so didn't notice. For a quick fix, you can just concatenate strings as you do withimwrite.