MATLAB: Writing binary file segment by segment

append data to binary filesmultispectral images

hi,
i am wondering if i can carry out the following task in matlab:
i have a large multiband image that is >10 GB. since i cannot open the entire image due to limited memory, i want to open the image row by row, ie if my image is R rows by C columns by B bands, i want to open 1 row x C columns x B bands at any one time. i then want to carry out some mathematical analysis, which returns 2 values per pixel. i want to save the returned values to separate binary files, by writing them to the files row by row (again due to limited memory). this entire process is then looped over all the rows of the image, which means i will need some function/script to allow me to append data to existing files. at the end of the day, i just want to open the output files in another software.
can this be done? if so, pls let me know which functions i should work with. or even better, are there scripts on the File Exchange that allow me to do this?
thanks for any help.

Best Answer

Some hints:
1. Use multibandread with the 'Offset' parameter inside a loop. (Also look at multibandwrite).
2. Use raw file access functions like fopen, fread and fwrite in a loop.
Air code: (assumes data is in ordered in 'bil' (look at multibandwrite doc)).
fid_input = fopen('input.bin','rb');
fid_output = fopen('output.bin','wb');
for rowInd=1:1000
rowData = fread(fid_input, rowLength*NumBands,'precision');
processedData = processData(rowData);
fwrite(fid_output, processedData,'precision');
end
fclose the handles.