Passer une variable entre 2 fonctions
Comment passer une variable d'une fonction a une autre?
Erreur:
?? Undefined function or variable 'I'.
Error in ==> testnoise>pushbutton2_Callback at 102
J = imnoise(I,'salt & pepper',0.02);
Error in ==> gui_mainfcn at 75
feval(varargin{:});
Error in ==> testnoise at 43
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback.
C'est une application qui a :
-3 buttons and 3 axes
Boutton1(pushbutton1) -conversion to gray et affichage en axes1
-- Second button(pushbutton2) -application salt&pepper noise pour l'image et affichage en axes2
-- pushbutton3-eliminer noise et afficher image en axes3
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
function pushbutton1_Callback(hObject, eventdata, handles)
RGB = imread('test.jpg');
I = rgb2gray(RGB);
axes(handles.axes1);
imshow(I);
end
function pushbutton2_Callback(hObject, eventdata, handles)
J = imnoise(I,'salt & pepper',0.02);
axes(handles.axes2);
imshow(J);
end
function pushbutton3_Callback(hObject, eventdata, handles)
L = medfilt2(J,[3 3]);
axes(handles.axes3);
imshow(L);
end |
Ma question c'est comment de passer une variable d'une fonction a une autre?
Par exemple variable I dans fonction pushbutton1 en pushbutton2. (dans mon cas)
Un petit exemple s'il vous plait.
Merci d'avance!
J'ai utilise setappdata et getappdata
Comment passer la variable dont j'ai besoin dans la fonction2. Passer variable I entre fonction1 et fonction 2 ?
J'essaye comme ca:
Code:
1 2
|
SETAPPDATA(H, 'string', I) %j'ai mis ca dans le callback de la premiere fonction |
Code:
1 2 3
|
GETAPPDATA(H, 'string', I)
%j'ai mis ca dans le callback de la deuxieme fonction |
Donc en nettoyant les deux fonctions (1 et 2) ca devient:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
function pushbutton1_Callback(hObject, eventdata, handles)
SETAPPDATA(H, 'string', I);
RGB = imread('test.jpg');
I = rgb2gray(RGB);
axes(handles.axes1);
imshow(I);
end
function pushbutton2_Callback(hObject, eventdata, handles)
GETAPPDATA(H, 'string', I);
J = imnoise(I,'salt & pepper',0.02);
axes(handles.axes2);
imshow(J);
end |
Il est bien comme ca?
J'attends un reponse s'il vous plait!
Merci d'avance!
Michel