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 view (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 7 Dec 2015
Edited: Walter Roberson on 7 Dec 2015
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

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!