Is there a way to control two subplots with one slider?
7 views (last 30 days)
Show older comments
Answered: Geoff Hayes on 2 Jun 2022
Can anyone demonstrate a way to update both subplots with one uicontrol slider?
In my case I have two matlab arrays with size (1024,128,20). I want to imshow 2d images of size 1024 x 128 for each of the third dimension using a slider and only one slider updating both subplots.
Thanks in advance
Geoff Hayes on 2 Jun 2022
@Derrell Dsouza - I think the issue is with your call to imagesc where you are not specifiying the axes upon which to draw the image. In fact, the slider callback is doing the following
h.ax(1) = imagesc(x_axis,y_axis,inst); colorbar
% other code
h.ax(2) = imagesc(x_axis,y_axis, lg ); colorbar;
which replaces the handles to the axes with the image object (while incorrect, because the h isn't actually updated via guidata then the axes handles are maintained for subsequent calls to this function).
The above code can be changed to specify which axes you want to update
imagesc(h.ax(1), x_axis,y_axis,inst); colorbar
% other code
imagesc(h.ax(2), x_axis,y_axis, lg ); colorbar;
The above should fix the issue and so both subplots should be updated (it worked for me). I do recommend placing all of this code within a (main) function rather than using a script so that your callbacks have access to the local variables defined in the main function (like h)...this avoids the need for calls to guidata.
More Answers (0)
Find more on Migrate GUIDE Apps 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!