Hey Shawn,
The issue you are encountering sounds like it is related to the way MATLAB's zoom functionality is interacting with the dynamic updating of your axes limits. When you zoom and then use the "restore view" feature, it is likely reverting to the view state (including axes limits) that was saved at the time of the initial plot or the last time the zoom tool's "save view" state was explicitly updated.
To ensure that the axes limits update correctly when you switch datasets and still allow for zooming and restoring the view to the appropriate state for the current dataset, consider the following approach:
1. Explicitly Update Zoom State After Plotting New Data:
After updating the plot with the new dataset and setting the axes limits, explicitly update the zoom tool's "save view" state to match the current view. This way, when the user restores the view after zooming, it should revert to the correct, most recently set axes limits.
2. Use Callbacks to Manage Axes Limits:
Ensure that the axes limits are updated both after initially plotting the data and after any zoom actions. You might need to use callback functions associated with the zoom actions to reset the axes limits dynamically based on the currently selected dataset.
In order to achieve the above approach you can follow below steps:
Step 1: Update Plot and Axes Limits for New Data
When you select a new dataset from the dropdown menu, you likely have a callback function that handles the plotting. After plotting the new data and setting the axes limits, add a command to update the zoom tool's state.
plot(app.UIAxes, newDataX, newDataY);
app.UIAxes.YLim = [min(newDataY), max(newDataY)];
zoomObj = zoom(app.UIFigure);
zoomObj.ActionPostCallback = @(obj,evd) updateAxesLimits(app, evd.Axes);
For more information on 'zoom' function refer following documentation:
Step 2: Define a Function to Update Axes Limits Based on Current Data
You might need a dedicated function to correctly set the axes limits based on the current dataset, especially if you are allowing to zoom and then want to programmatically restore to the dataset-specific view.
function updateAxesLimits(app, axesHandle)
newYLim = [min(app.currentDataSetY), max(app.currentDataSetY)];
axesHandle.YLim = newYLim;
Step 3: Adjust Zoom Callbacks if Necessary
Depending on your app's structure and the specific user interactions, you might need to adjust how and when you attach callbacks to the zoom object, ensuring they correctly reflect the current state and data.
Ensure that `app.currentDataSetY` (or however you choose to track the current dataset or its limits) is updated every time the dataset changes.
Hope the above steps resolve your issue!