Is there a way to control two subplots with one slider?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Derrell Dsouza
el 1 de Jun. de 2022
Respondida: Geoff Hayes
el 2 de Jun. de 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 comentarios
Geoff Hayes
el 1 de Jun. de 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.
Respuesta aceptada
Geoff Hayes
el 2 de Jun. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!