Is there a way to control two subplots with one slider?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Derrell Dsouza
le 1 Juin 2022
Réponse apportée : Geoff Hayes
le 2 Juin 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
2 commentaires
Geoff Hayes
le 1 Juin 2022
@Derrell Dsouza - did you create your GUI programmatically, using App Designer or using GUIDE? Have you created a callback for your slider? You should be able to update both subplots from within that callback. Please provide a sample of code that shows what you have attempted.
Réponse acceptée
Geoff Hayes
le 2 Juin 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!