imshow and Scatter in GUIDE

3 visualizaciones (últimos 30 días)
Márcio Marques
Márcio Marques el 12 de Sept. de 2017
Editada: OCDER el 14 de Sept. de 2017
Hello everybody, I have lost many hours and I can not find the problem, if someone can help me, I thank you immensely.
I have a program that shows an image at the beginning, then pressing a key, refresh the image (constantly), pressing another key, displays a new image. I'm working with imshow and Scatter, but apparently, they do not relate well, because when I present first the imshow image, the hScatter variants cease to exist and error appears.
this is the initialization:
and this is the Loop:
when i press first "state_3d_view" everything is OK, but if i press "state_3d_view" and then "state_depth_view" and again "state_3d_view" appear the below error!!
i know that the problem is the imshow, because i already commented "set(imshow(depth,[0 outOfRange]),'CData',depth);" and the program and variables works weel.
the error:
Thank you for all the help you can offer.

Respuestas (2)

OCDER
OCDER el 12 de Sept. de 2017
Editada: OCDER el 14 de Sept. de 2017
Calling imshow can delete the previous axes handle (which is your handles.axes1 and thus your hScatter too).
The following examples shows how imshow deletes handles.
a = axes;
b = imshow(ones(100), 'parent', a); %Show white image
imshow(zeros(100)); %Show black image, BUT deletes previous handles!
a =
handle to deleted Axes
b =
handle to deleted Image
To avoid deleting handles, directly change 'CData' of the image handle.
a = axes;
b = imshow(ones(100), 'parent', a); %Show white image
set(b, 'CData', zeros(100)); %Show black image, but no handles are deleted
So in your code, instead of this:
set(imshow(depth, [0 outOfRange]), 'CData', depth) %Which deletes hScatter when imshow is called.
try this (assuming the image handle is named ImHandle):
set(ImHandle, 'CData', depth) %Doesn't delete any handle
You can also use two separate handles on the GUI, like handles.axes1 and handles.axes2. Store the scatter on handles.axes1 ( using scatter(handles.axes1, ...) ), and image on handles.axes2 ( using imshow(...,'Parent', handles.axes2) ). If you want the image/scatter to be at the same place, use the handles.axesN.Visible = 'on' or 'off' to show or hide the the correct axes in the GUI.
  11 comentarios
Márcio Marques
Márcio Marques el 14 de Sept. de 2017
Thank you Donald Lee.
I didn't get it with only one Handles.axes1, so I joined another handles.axes2, and the problem was solved. Either way, the same question remains on the air, and one day I try to get around it again. Thank you for all the explanations.
OCDER
OCDER el 14 de Sept. de 2017
Editada: OCDER el 14 de Sept. de 2017
You're welcome!

Iniciar sesión para comentar.


Márcio Marques
Márcio Marques el 12 de Sept. de 2017
Hello Donald Lee,
thank you for your reply and your explantion !! i tried do what you write, but appear the same error
Am I doing something wrong?
Thank you so much. .
  2 comentarios
Walter Roberson
Walter Roberson el 12 de Sept. de 2017
It makes it more difficult for us to fix the code when you post images of the code instead of the code itself.
Before the loop, initialize a loop counter to 0.
Inside the loop, add 1 to the loop counter.
Replace the call
ter = imshow(depth, [0 OutOfRange]);
set(ter, 'CData', depth)
with
if loop_counter == 1
ter = imshow(depth, [0 OutOfRange]);
else
set(ter, 'CData', depth');
end
Márcio Marques
Márcio Marques el 12 de Sept. de 2017
Thank you. yes, i understand, sorry!
I already did this, but appear the same error :(

Iniciar sesión para comentar.

Categorías

Más información sobre Specifying Target for Graphics Output 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!

Translated by