Hi there,
I am trying to make use of datacursormode to select points/regions I am interested in and displaying the x, y, and rgb values at that point. This is the code I have used and the function to generate the position at the location I have selected. However, I can't seem to be able to generate the RGB values when I umcomment the line CData and it shows "unable to update datatip using custom update function".
figureimagesc; axis image;datacursormode ondcm = datacursormode(gcf);set(dcm,'UpdateFcn',@myupdatefcn_example)function txt = myupdatefcn_example(trash,event)pos = get(event,'Position');I = get(event, 'DataIndex');% CData = get(event,'CData');
txt = {[num2str(pos(1))],... [num2str(pos(2))],... [num2str(I)]};end
Next, I would also like to draw a rectangle and extract the mean RGB values within that rectangle using the datacursormode as well so that it is interactive. I found this drawrectangle function that allows me to draw the rectangle I want on the image, and also generates the position of the box. However, I am not quite sure how to link this up with the datacursormode.
figureimagesc; axis image;roi = drawrectangle('Color',[1 0 0]);addlistener(roi,'MovingROI',@allevents);function allevents(src,evt) evname = evt.EventName; switch(evname) case{'MovingROI'} disp(['ROI moving previous position: ' mat2str(evt.PreviousPosition)]); disp(['ROI moving current position: ' mat2str(round(evt.CurrentPosition))]); case{'ROIMoved'} disp(['ROI moved previous position: ' mat2str(evt.PreviousPosition)]); disp(['ROI moved current position: ' mat2str(evt.CurrentPosition)]); endend
Could anyone please advise? Thank you for your time.
Best Regards,
Wayne
Best Answer