MATLAB: Error on ind2rgb

ind2rgbindex exceeds matrix dimensions

Greetings everyone.
[X, MAP] = imread('test.jpg');
RGB = ind2rgb(X,MAP);
LAB = rgb2lab(RGB);
Here I tried to convert from index to RGB image using 'ind2rgb' command, but the result is like this: Index exceeds matrix dimensions.
Error in ind2rgb (line 26) r = zeros(size(a)); r(:) = cm(a,1);
I already tried to looking for the solution on the internet, but I couldn't find it.
Hope someone who knew how to fix it, kindly give me a lead here.
Here I also attached the file that I used for this command.
Thank you before.

Best Answer

Try this:
[RGB, MAP] = imread('test.jpg');
[X,map] = rgb2ind(RGB,32) ;
RGB = ind2rgb(X,map);
LAB = rgb2lab(RGB);