I have a function which works with a file selected from the user using a an edit callback. The function does not work inside the funtion callback, how can I put my function out side the function callback?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a function that works with an image the user selects (measure11). The user pastes the path of that image in a UI edit (uicontrol('style','edit',...)). The problem is that for some reason, the function that works with the image does not work when it is inside the function callback of the edit. I need to do a "trick" to make the function work with the image right when the user selects an image but so it is not inside de function callback
This is what I have so far
function temmporal
filename=0;
f = figure('Visible','on','Position',[360,500,450,185],'NumberTitle','off','ToolBar','none','MenuBar','none','Color',[0.95 0.95 0.95]);
hEdit = uicontrol('Style','edit','Position',[25 50 400 20], 'Callback',@edit_Callback);
while exist('filename','var')==1
edit_Callback
x=measure11(filename);
break
end
function edit_Callback(source,eventdata)
a = get(hEdit,'string');
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.tiff';'*.png'} ,...
'Select file to be analyzed',a); close all
end
end
But clearly using a "while" loop did not work. The function that works with the image is the one called "measure11" and the image itself is called "filename".
This makes the function (measure11) not work properly:
function edit_Callback(source,eventdata)
a = get(hEdit,'string');
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.tiff';'*.png'} ,...
'Select file to be analyzed',a); close all; x=measure11(filename);
end
In this case the function (measure11) works alright but will run when the user hasn't selected an image yet:
x=measure11(filename);
function edit_Callback(source,eventdata)
a = get(hEdit,'string');
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.tiff';'*.png'} ,...
'Select file to be analyzed',a); close all
end
댓글 수: 0
답변 (1개)
Walter Roberson
2015년 12월 7일
편집: Walter Roberson
2015년 12월 7일
You are not saving the filename or pathname after you obtain them from the user. See http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!