Last Axes Display Image
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Plus de réponses (2)
Nathan Greco
le 1 Juil 2011
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 commentaires
Jan
le 7 Juil 2011
@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
le 7 Juil 2011
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.
3 commentaires
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output 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!