imshow and Scatter in GUIDE

3 次查看(过去 30 天)
Márcio Marques
Márcio Marques 2017-9-12
编辑: OCDER 2017-9-14
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.

回答(2 个)

OCDER
OCDER 2017-9-12
编辑:OCDER 2017-9-14
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 个评论
Márcio Marques
Márcio Marques 2017-9-14
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 2017-9-14
编辑:OCDER 2017-9-14
You're welcome!

请先登录,再进行评论。


Márcio Marques
Márcio Marques 2017-9-12
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 个评论
Walter Roberson
Walter Roberson 2017-9-12
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 2017-9-12
Thank you. yes, i understand, sorry!
I already did this, but appear the same error :(

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by