Azzera filtri
Azzera filtri

App Designer Callback function keeps resetting plot with a double click to position it is first set at.

4 visualizzazioni (ultimi 30 giorni)
Hello,
I recently converted an app originally designed in GUIDE into App Designer. I did not write the original code, and due to the conversion I'm at a bit of a lose on how to even search for an answer to this quiestion. I apologize if this has been covered elsewhere.
In my app, I can load txt files which contain signal data on a time scale. Using the app, I can scroll to a signal of interest. I then set the 'origo', or the origin of the signal with a Callback function, which replots the signal over a consistent timescale.
% Button pushed function: setorigo
function setorigo_Callback(app, event)
% Create GUIDE-style callback args - Added by Migration Tool
[hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
% set t-axis zero at first sync pulse
global origo t data
axes(handles.clickplot)
[origo,y]=ginput(1);
cla;
plot(t,log10(data.nix),'.');
set(handles.clickplot,'xlim',[origo origo+0.425],'xtick',[origo+0.0485:0.012:origo+0.425]','xgrid','on');
hold on
plot(origo,y,'or');
end
This works exactly like the old tool did, which is great. I can process the signal, and move on. The issue is when I zoom out, and then scroll to find my next signal of interest. If I at all double click anywhere on the plot, the plot zooms once again to the consistent timescale created by the setorigo_Callback function. Additionally, if I find other signals of interested and process them, including a setting a new origo location on the x-axis, if I double click at all it will zoom to the first origo time scale I specified. It doesn't matter if I've set a new origo, the double click will send me to the location of the first origo process when I first opened the app.
Here are my Zoom in and out functions:
% Clicked callback: uitoggletool2
function uitoggletool2_ClickedCallback(app, event)
% Reset the states of interactive tools and reset all figure
% interactions.
app.resetInteractions(event);
% Enable or disable zoom-out based on the
% tool's current state.
state = app.uitoggletool2.State;
zoomModeObject = zoom(app.figure1);
if state
zoomModeObject.Direction = 'out';
zoomModeObject.Enable = 'on';
else
zoomModeObject.Enable = 'off';
end
end
% Clicked callback: uitoggletool1
function uitoggletool1_ClickedCallback(app, event)
% Reset the states of interactive tools and reset all figure
% interactions.
app.resetInteractions(event);
% Enable or disable zoom-in based on the
% tool's current state.
state = app.uitoggletool1.State;
zoomModeObject = zoom(app.figure1);
if state
zoomModeObject.Direction = 'in';
zoomModeObject.Enable = 'on';
else
zoomModeObject.Enable = 'off';
end
end
Anyone have any idea what's going on here? Or futhermore, how I can stop it? I can't seem to clear the origo valuable, or wipe the plot's memory of the first origo set. Please let me know if you'd like to see other sections of the code.
Many thanks!

Risposta accettata

Emily T. Griffiths
Emily T. Griffiths il 12 Mar 2021
So taking some advice I got on StackOverflow, I made a new button that resizes the xlims, and other features, of the axes. Now, depending on whether I've last clicked 'set origo' or 'zoom to data', a double click will send me to each range, respectively. This means I can at least get out of the axes limits that set origo determines. I didn't spend the time to get rid of the auto xgrid, because honestly, I can live with it.
% Button pushed function: ZoomtoDataButton
function ZoomtoDataButtonPushed(app, event)
[hObject, eventdata, handles] = convertToGUIDECallbackArguments(app, event); %#ok<ASGLU>
axes(handles.clickplot)
cla;
updateplot(app, handles)
xlim('auto')
xticks('auto')
ylim('auto')
end

Più risposte (0)

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by