MATLAB Answers

0

How to assign each axes to hold/keep its own image?

Asked by Stelios Fanourakis on 8 Oct 2019
Latest activity Commented on by Rik
on 10 Oct 2019
Hi
I have this set of lines
set(get(gca,'children'),'cdata',squeeze(Img(:,:,S,:))); %% For Axes 1
set(get(gca,'children'),'cdata',squeeze(Img2(:,:,S2,:))) %% For Axes 2
set(get(gca,'children'),'cdata',squeeze(Img3(:,:,S3,:))) %% For Axes 3
But because of the hierarchy sequence I only get the Img3 at all axes. When I click upon each one of the axes I get the last image I assigned on this set of lines. How do I make it to keep its image for every each axes seperately? So Axes 1 should have Img, Axes 2 Img2 and Axes 3 Img3

  0 Comments

Sign in to comment.

1 Answer

Answer by Rik
on 8 Oct 2019
 Accepted Answer

You should never use gcf or gca in code for a GUI. As your tags indicate you're using GUIDE: use the explicit handles to the axes object stored in the handles struct.

  27 Comments

Ah, that one is on me, I edit the function header without checking if you were indeed not using eventdata (since I hardly ever use it).
function mouseScroll(hObject,~,I)
%change to
function mouseScroll(hObject,eventdata,I)
You should also confirm that you haven't changed the callback. Because if you haven't, the third input in a GUIDE-generated GUI is the handles struct.
Dear RIk
Thank you so much for your valuable contribution. My Viewer seems to work at the moment.
However the mouse scrolling stops only at the left end whereas at the right end of the slider I get the error
Warning: 'slider' control cannot have a 'Value' outside of 'Min'-'Max' range
Control will not be rendered until all of its parameter values are valid
Index exceeds matrix dimensions.
Error in experiment/mouseScroll (line 259)
set(i1,'cdata',squeeze(im2(:,:,S(1),:))); %%For Axes 1
Error while evaluating Figure WindowScrollWheelFcn.
Use the debugger. Follow the flow of your program. Find out where the properties of your slider are set. Find out when the results are different from what you expect.
The warning you see tells you that some code is setting the value property to something bigger than max. And then you get error that tells you your index is too big. That means either my code doesn't work, or the size is not retrieved correctly. Check both options.

Sign in to comment.