Problem related to locked axis.
Show older comments
I am having a problem related to the locked axis. I have a figure with a plot i.e. sin(x). Then I MANUALLY zoom in on an interested region (ROI). For i.e. [9 12 -1 -0.4]. After I press the button 'Test' I plot a statement in the same figure (not holding on) like for ie. cos(x) and I want to automatically go (zoom in) to my ROI. With the bottom code it works, but when I want to see the full view of the plot by double-clicking in the Zoom in, ou using the Zoom out, the axis is lockedon that region and I can't check the whole plot again. Any Help? Thanks in advance
figure
x=1:20;
plot(x, sin(x))
h = uicontrol('units', 'normalized','Position',[0.02 0.05 0.07 0.1],'String','Test');
h.Enable = 'Inactive';
h.ButtonDownFcn = ['axzoom=axis; '...
'cosx=cos(x);'...
'plot(x, cosx, ''r'');'...
'axis(axzoom);'];
6 Comments
Rik
on 2 Nov 2017
I don't really have a solution for you, but I do have a remark: if you don't need dot-notation, don't use it. If you use get and set, your code should still be compatible with HG1 releases of Matlab (R2014a and earlier). Sometimes the difference is a bit more than only the syntax, in which case you can use this FEX submission to write code for both. </shameless self promo >
Adam
on 2 Nov 2017
I always use dot notation whenever I can as I am used to it with writing my own classes so it is intuitive and we don't care about supporting old versions of Matlab in our code!
Rik
on 2 Nov 2017
R2014a is not that old yet, but that is your personal call of course. I've seen someone using R2006a, because there wasn't budget for an upgrade for him. As Jan Simon also sometimes mentions: in academia reproducibility is important on the long term (think 10 years). In other fields, reproducibility may not be required on such a long time scale, but still.
Also, if your code is compatible with old code, there is a very good chance it will stay compatible with even newer version. It forces you to take a bird's eye view of what you are attempting to do.
Personally, I check my functions on R2012b (the first release with the ribbon) and Octave. And yes, sometimes that leads to writing (part of) a function three times, but at least everyone can use my code.
Rafael Freire
on 2 Nov 2017
Forward compatibility is far less constraining than backwards compatibility. The latter implies never using any of the new functionality that has come out since the version you want to be backward compatible with, or constantly providing branched code to deal with older versions. For people writing code for the File Exchange this may be important, but for a company like mine we upgrade to the new version each time and even if we didn't we would never go back to an older version than the one we have right now, even if, for some reason, we stopped upgrading.
As with most things in software engineering, it all depends on what you need. Making code compatible with things it doesn't need to be compatible with, writing code more generic than it needs to be, adding features that you might want in the future, but don't need right now, etc, can all add time to development that is unnecessary.
So our company's code is aimed to be usable in R2017a and R2017b. I certainly pity anyone who has to make all their code compatible with every version back to R2006a, which is, coincidentally, the first version I started working with I think!
Rafael Freire
on 2 Nov 2017
Answers (1)
Adam
on 2 Nov 2017
Adding
zoom reset
after plotting the original will remember that as the current zoom which it will then zoom back out to. I have still had problems in the past even when using this, but I can't remember the exact scenario is or whether they would be relevant to what you are doing. I was programming manuall zoom callbacks and a variety of other things too.
4 Comments
Rafael Freire
on 2 Nov 2017
Adam
on 2 Nov 2017
And does this not work in that case?
Rafael Freire
on 2 Nov 2017
Rafael Freire
on 2 Nov 2017
Edited: Rafael Freire
on 2 Nov 2017
Categories
Find more on Data Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!