MATLAB: Select an image inside a figure select image mouse figure Hello everyone I have to select one image within a figure (in which there are 4 pictures) and save the result. Can anyone help me? Thanks a lot F Best Answer something like this can be implemented.function interactiveplot() % 4 images hax(1)=subplot(2,2,1);imagesc(rand(20,10)); title('image1') hax(2)=subplot(2,2,2);imagesc(rand(30,20));title('image2') hax(3)=subplot(2,2,3);imagesc(rand(40,30));title('image3') hax(4)=subplot(2,2,4);imagesc(rand(50,40));title('image4') % create a context menu (right click) for ind=1:length(hax) hcmenu(ind) = uicontextmenu; set(hax(ind),'userdata',ind); %tag which subplot is which %create the save listing in the context menu, passing it the %callbackfunction savesub to save with the associated subplot %handle item = uimenu(hcmenu(ind),'Label','save subplot','Callback',{@savesubs hax(ind)}); %set what the context menue will be assigned to. % set(hax(ind),'uicontextmenu',hcmenu(ind)) %not sure if needed % seems to work without it set(get(hax(ind),'children'),'uicontextmenu',hcmenu(ind)) end end%function that does the savingfunction savesubs(h,event,hax) %figure out where and what you want to call the image [file folder] = uiputfile('*.jpg'); %create new figure to display. if not all subplots will be saved hfig = figure; hax_new = copyobj(hax, hfig); set(hax_new, 'Position', get(0, 'DefaultAxesPosition')); %save the copied plot as a jpg. saveas(hfig,file,'jpg') %close the new plot close(hfig);end Related SolutionsMATLAB: ButtonDownFcn on Axes after imshow Make sure that hittest and pickableparts is set for the axes.imshow() does a lot of things behind your back. I prefer to use image() MATLAB: How to Call Context Menu from Inside a Rectangle If you set the FaceColor of the rectangle, the uicontext menu works anywhere inside. Be aware that this may complicate other things you're trying to do. Related QuestionMake the XTickLabel mouse sensitive in UIAxesAll figures in subplot saved to animated gif file.Customize Wheel Scroll fxn to work within axes in figureR2019b tiled layoutGca when using subplots
Best Answer