Last Axes Display Image
1 次查看(过去 30 天)
显示 更早的评论
Hi very simple, but I can not :(
See here%%%%
"
function Axes
N.fh=figure('unit','pix',...
'Position',[400 300 300 300],...
'MenuBar','None',...
'Resize','off',...
'Name','Axes Find problem',...
'Numbertit','off');
N.img1 = axes('Parent',N.fh,...
'Unit','pix',...
'Position',[20 100 100 100]);
N.img2 = axes('Parent',N.fh,...
'Unit','pix',...
'Position',[180 100 100 100]);
N.Push(1) = uicontrol('style','push',...
'position',[45 220 50 30],...
'Stri','image 1',...
'backgr',[0.90 0.90 0.90],...
'Callback',{@Push_1,N});
N.Push(2) = uicontrol('style','push',...
'position',[205 220 50 30],...
'Stri','image 2',...
'backgr',[0.90 0.90 0.90],...
'Callback',{@Push_2,N});
set([N.img1,N.img2],'CreateFcn',{@Image_CreateFcn,N})
function Image_CreateFcn
function Push_1(varargin)
N.Damage1=imread('cat.jpg');
axes(N.img1) %%%%ERROR
imshow(N.Damage1);
function Push_2(varargin)
N.Damage1=imread('dog.jpg');
axes(N.img2) %%%%ERROR
imshow(N.Damage1);
"
0 个评论
采纳的回答
更多回答(2 个)
Nathan Greco
2011-7-1
You have a scope issue. Try doing this instead (note the "end"s)
function Axes
N.fh=figure('unit','pix',...
'Position',[400 300 300 300],...
'MenuBar','None',...
'Resize','off',...
'Name','Axes Find problem',...
'Numbertit','off');
N.img1 = axes('Parent',N.fh,...
'Unit','pix',...
'Position',[20 100 100 100]);
N.img2 = axes('Parent',N.fh,...
'Unit','pix',...
'Position',[180 100 100 100]);
N.Push(1) = uicontrol('style','push',...
'position',[45 220 50 30],...
'Stri','image 1',...
'backgr',[0.90 0.90 0.90],...
'Callback',{@Push_1,N});
N.Push(2) = uicontrol('style','push',...
'position',[205 220 50 30],...
'Stri','image 2',...
'backgr',[0.90 0.90 0.90],...
'Callback',{@Push_2,N});
set([N.img1,N.img2],'CreateFcn',{@Image_CreateFcn,N})
function Image_CreateFcn
end
function Push_1(varargin)
N.Damage1=imread('cat.jpg');
axes(N.img1) %%%%ERROR
imshow(N.Damage1);
end
function Push_2(varargin)
N.Damage1=imread('dog.jpg');
axes(N.img2) %%%%ERROR
imshow(N.Damage1);
end
end
Your N structure was not able to be reached in all of the functions without passing it into the different functions. By containing everything within 1 main function, your N structure is accessible by all subfunctions (your callbacks).
4 个评论
Jan
2011-7-7
@nsbd: Do not use "Axes" as name of a function. It is confusing, because "axes" is a built-in function already.
Please explain, why you do not "want" to use the Nathan's working solution.
Jan
2011-7-7
You've sent me an email with a link to this thread. I really do not like to get such emails.
If I find the time to read a question and I have an answer, I will post it. If I do not post an answer, I either do not have the time to read it, or I do not have an answer. In both cases reading and deleting your email is a waste of time for me.
Instead of annoying the contributors, it would be a much better strategy to include a question in your post. See: How to ask a question and How do I write a good question.
Please care about Nathan's answer.
另请参阅
类别
在 Help Center 和 File 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!