GUIDE scrollfunction deleting figure

4 views (last 30 days)
Brian
Brian on 10 Dec 2014
Commented: Brian on 17 Dec 2014
Hello, I have a question about my scrollfunction, I asked it here before but couldn't get a good response.
My question is this: I have a scrollfunction that works and works well. I have a gui I made in GUIDE with four axes, and the scrollfunction will change depending on the axes. My problem is this: depending on the rate at which I scroll, the figure can bug out and delete itself. After running some tics and tocs, I found the problem lies with how fast everything gets plotted.
When I scroll slower than it takes MATLAB to plot (~0.1/sec, meaning I can scroll upwards at 10 slices per second). When I scroll at a rate that would replot more than 10 times a second, it bugs out. THe reason I'm asking this, and just assuming its a MATLAB problem, is I have a separate duplicate programmatic GUI that does a identical process, with more or less the same code, that doesn't have this problem. I think the problem is within GUIDE.
Is this common, or is there a workaround? I tried to implement a pause of 0.1 seconds to try to get this bug to not occur, no dice. Regardless of what I do, whenever I try to scroll quickly, I have the figure deletion.
Thanks!
EDIT: Here are some segments of code from my UI. My scrolling function uses the mouse scroll wheel to go upwards and downwards in slices in a 3D matrix axially, sagittally and coronally by clicking on whatever GCA I want to sift through. My data consists of response data which I image in imagesc, and is again constructed in a 3D matrix. It represents a volume I export from a FEA utility.
I have attached the code to this question now as opposed to using gist.
These are the relevant graphics functions I employ at the moment. Besides that, here are some UI screenshots to help you get an idea of what my UI looks like:
And here is the error message I get when I scroll too quickly:
Error using drawnow
Error while evaluating DestroyedObject WindowScrollWheelFcn
Error using matlab.ui.Figure/set
Invalid or deleted object.
Let me know if you'd like me to upload anything else.
  7 Comments
Brian
Brian on 14 Dec 2014
I can do that, again I will edit my original post. I can't attach my data though, that I use to visualize, as even zipped its over 10MB.

Sign in to comment.

Accepted Answer

matt dash
matt dash on 12 Dec 2014
Edited: matt dash on 12 Dec 2014
Ok, I'm not sure exactly what's causing your problem, but it is quite likely the cla resetting something that shouldn't be reset.
But that's tangential to the real cause of the problem, which is that you're clearing and completely redrawing the image every time you scroll the wheel. You don't need to do that, and more importantly you really don't want to be doing that, because as you can see it can lead to all kinds of unintended side effects.
What you really want do do is just be setting the cdata and alphadata of the existing image. This has two benefits: 1) it is much much faster than clearing and resetting. 2) it can't have any nasty side effects.
The only potentially tricky thing is that since you're using imagesc, you may need to be scaling your image data manually before plotting it. But that shouldn't take more than a couple lines of code to solve (basically just normalizing your data to match the size of the color map.
I have attached a demo function that shows how to make this work (minus the scaling... you can figure that out). Note how in the scroll function ONLY the cdata gets set. The image is only created once, in what is effectively the "openingFcn" at the top of the code. (Demo file doesnt show setting alphadata, but it works exactly like setting the cdata)
Side note: you know instead of using setappdata you can just store things in handles and retrieve them with guidata? This is generally faster (since all gui functions set/get handles already), and requires less code.
  3 Comments
Brian
Brian on 17 Dec 2014
Thank you for your help in this. I think I have enough for now, and your advice has been very helpful.
I would like to learn to ditch GUIDE eventually, but the conveniences it provides (precise gui placement of buttons, etc) are hard to replicate.
Thats my problem though: thanks again for all your help!

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 11 Dec 2014
Exactly what is getting scrolled? Do you have a slider/scrollbar and are changing it, which changes some parameter which then causes a plot/graph/chart/image to change? Or do you have a scrollpanel for an image and you're scrolling the image (like in attached demo)?
Well, whatever it is or however you're doing it, maybe try putting in a "drawnow" at a strategic place to force update of the display. You might also want to totally reset the axes with a "cla reset" in between separate scroll operations.
  3 Comments
Brian
Brian on 12 Dec 2014
I'll edit my original post to include screenshots and I'll post my code. Sorry, probably should have done so in the first place.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!