필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
AFFY
AFFY 2015년 4월 4일
댓글: AFFY 2015년 4월 5일
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
Geoff Hayes
Geoff Hayes 2015년 4월 4일
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 2015년 4월 5일
편집: AFFY 2015년 4월 5일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 4월 5일
편집: Geoff Hayes 2015년 4월 5일
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
AFFY
AFFY 2015년 4월 5일
what could be used instead of the identifier 'filename' ?
AFFY
AFFY 2015년 4월 5일
it worked. thanks a lot for your help

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by