Description of the problem
The data cursor does not work for image objects plotted in App Designer (or in any uifigure) prior to r2020B. AppDesigner features are still being rolled out with every release of Matlab. For example, data tips have been implemented in r2020a. But for image objects, the datacursor still does not work (prior to r2020B). Here is a demo of the problem using a legacy figure and a uifigure.
imageData = randi(100,10,12);
dcm = datacursormode(fig);
title(ax, 'Legacy figure')
uiax = uiaxes(uifig, 'Position', [10 10 500 410]);
uiax.Colormap = jet(100);
dcm = datacursormode(uifig);
As you can see, the datacursor appears as exected in the legacy figure but in the uifigure, a message appears, Unrecognized method. property, or field 'ColorSpace' for class 'matlab.ui.control.UIAxes'
Solution
Create a custom update function for the datacursor object within the UIAxes/UIFigure. This demo shows how to recreate the datacursor text produced in the legacy figure using UIFigures anbd UIAxes.
Continuing from the example above,
dcm = datacursormode(uifig);
dcm.UpdateFcn = @(hObj,event,ax)localDcmFcn(hObj,event,uiax);
function txt = localDcmFcn(~,event,ax)
idx = event.Target.CData(event.Position(2),event.Position(1));
txt = sprintf('[X,Y] [%d %d]\nIndex %d\n[R,G,B] [%.4g %.4g %.4g]', ...
event.Position, idx, ax.Colormap(idx,:));
Now the datacursor should appear the same in the legacy figure and the uifigure/app. The only difference may be the number of decimal places shown in the RGB values.
Solution using scaled images
Scaled images (i.e. imagesc()) must use different indexing that scales the CData values to the colormap values. This demo shows how to achieve similar results to the demo above using scaled images. Note that I.CDataMapping is scaled in the image object. This demo added on Jan 2022.
X = linspace(0,2*pi,size(Z,2));
Y = linspace(0,2*pi,size(Z,1));
uiax.Colormap = jet(100);
dcm = datacursormode(uifig);
dcm.UpdateFcn = @(hObj,event,ax)localDcmFcn(hObj,event,uiax);
function txt = localDcmFcn(~,event,ax)
[~, xidx] = min(abs(event.Target.XData - event.Position(1)));
[~, yidx] = min(abs(event.Target.YData - event.Position(2)));
colorbarValue = event.Target.CData(yidx, xidx);
colormapIdx = round((colorbarValue - ax.CLim(1))/(ax.CLim(2)-ax.CLim(1)) * (size(ax.Colormap,1)-1) +1);
txt = sprintf('[X,Y]: [%.2g, %.2g]\nCBar Value: %.2g\n[R,G,B]: [%.4g, %.4g, %.4g]', ...
event.Position, colorbarValue, ax.Colormap(colormapIdx,:));