Effacer les filtres
Effacer les filtres

how to call functions saved in other m.file in gui?

1 vue (au cours des 30 derniers jours)
AFFY
AFFY le 4 Avr 2015
Commenté : AFFY le 5 Avr 2015
If we access functions that are not in-built in MATLAB but stored manually, it gives error in GUI. The same functions are running normally without GUI.
function recog_Callback(hObject, eventdata, handles)
I= getappdata(0,'I');
.
.
.
img1=(im2bw(I,0.9));
img2=(im2bw(r,0.9));
[mssim ssim_map] = ssim_index(img1, img2);
where ssim_index is a function stored in another m file. I am getting error Output argument "mssim" (and maybe others) not assigned during call to "D:\codes\ssim_index.m>ssim_index".
  2 commentaires
Geoff Hayes
Geoff Hayes le 4 Avr 2015
AFFY - the error message suggests that there is something (perhaps) failing in your ssim_index function and so the outputs are not being assigned. Put a breakpoint at the line
[mssim ssim_map] = ssim_index(img1, img2);
and re-run your GUI and wait until the debugger pauses at this line. Check the inputs img1 and img2 - are they valid? Also verify that ssim_index function does in fact return two outputs. If it does, look at this function to see why it may exit before the outputs are set.
AFFY
AFFY le 5 Avr 2015
Modifié(e) : AFFY le 5 Avr 2015
from the breakpoint i got to know that img1 is empty.
but i wrote
img1=(im2bw(I,0.9)); in the same function and the variable I ws assigned an image in the another pushbutton callbacK. I also wrote setappdata(0,'filename',I); so as to use that I variable in a different function. but it seems that variable I value din't get assigned. how to do that?

Connectez-vous pour commenter.

Réponses (1)

Geoff Hayes
Geoff Hayes le 5 Avr 2015
Modifié(e) : Geoff Hayes le 5 Avr 2015
AFFY - you mention that img1 where
img1=(im2bw(I,0.9));
and that I was assigned an image in another pushbutton callback as
setappdata(0,'filename',I);
Note that setappdata (as used above) sets the image I to be uniquely identified by 'filename'. And so if you wish to retrieve this image in another callback, you would need to do
I = getappdata(0,'filename');
rather than the
I = getappdata(0,'I');
as 'I' is not a valid identifier for any data saved to the graphics object identified by zero. Change your getappdata call to
I = getappdata(0,'filename');
and step through the code once again. You should be able to get an image (though you may want to consider renaming the identifier from 'filename' to something else that indicates that this is an image).
  2 commentaires
AFFY
AFFY le 5 Avr 2015
what could be used instead of the identifier 'filename' ?
AFFY
AFFY le 5 Avr 2015
it worked. thanks a lot for your help

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks 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!

Translated by