Q:

OCTAVE - ind2rgb: X must be an indexed image

I am trying to plot and save some meteorological data into png image files using the following lines.
imag = data2image(flipud(vari'));
imag = gray2ind(imag);
imwrite(imag,colormap('jet'),'PSFC_RIO_im.png','png');

where data2image is a custom function that re-scales the data to be usable by image functions.
function image = data2image(data)
    HIGH = max(data(:));
    LOW = min(data(:));
    image = (data - LOW)/(HIGH-LOW);
end

Unfortunately the imwritecomplains with the following error:
error: ind2rgb: X must be an indexed image
error: called from:
error:   /usr/local/share/octave/3.6.4/m/image/ind2rgb.m at line 44, column 5
error:   /usr/local/share/octave/3.6.4/m/image/imwrite.m at line 176, column 16
error:   /home/tufts/Documents/Octave/geomat.m at line 53, column 1

Where line 53 is the imwrite in the code above. This error makes absolutely no sense to me, as imag was converted to an indexed image with the gray2ind function. I also tested this by plotting with imshow, which works.
EDIT - class of imag:
octave:9> class(imag)
ans = double

A:

I am going to answer my own question after accidentally, in an unrelated problem, figuring out how.
Indexed images in MATLAB have a minimum value of 1. My function was getting the minimum value of the data, and making that equal to 0.
Take care of that, and you solve the problem

