How to update values across functions in a GUI

4 views (last 30 days)
I'm currently working on a program for image processing. The window has two displays: one for the full size of the images in coming, and one for a zoomed-in portion the photo. I have a text display with two buttons which control a bias for the zoom.
(EDIT: It may help to say that I am grabbing these images from IP Cam, so anytime you go to the web address, the current image from the camera is grabbed. By doing this with a while loop repeatedly, a low frame rate feed is created)
Currently, I have to stop the feed, change the bias, and then start the feed again to see the changes. How can I make it so I can change the value and have it update live? Here is the code for the feed:
% --- Executes on button press in previewButton2.
function previewButton2_Callback(hObject, eventdata, handles)
% hObject handle to previewButton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of previewButton2
%this code is for the right-hand button
button_state2 = get(hObject,'Value');
if button_state2 == get(hObject,'Max')
%display('down');
handles.button2 = 1;
while handles.button2 > 0
%read image from URL
image = imread(handles.IPshot{1},'jpg');
%rotate if requested
switch handles.rotateImg
case 'left'
image = imrotate(image,-90);
case 'right'
image = imrotate(image,90);
case 'down'
image = imrotate(image,-180);
end
%run full picture simultaneously if requested
isChecked = get(handles.runSimul,'Value');
if isChecked
axes(handles.previewFrame);
imagesc(image); axis image;
end
%crop the photos as they come
[sizeX, sizeY] = size(image);
cropX = ((sizeX/2)-handles.bias):((sizeX/2)+handles.bias);
cropY = ((sizeY/2)-handles.bias):((sizeY/2)+handles.bias);
colormap(gray);
axes(handles.previewFrame2);
imagesc(image(cropX,cropY)); axis image;
%see if it's time to stop
button_state2 = get(hObject,'Value');
if button_state2 == get(hObject,'Min')
handles.button2 = 0;
end
end
elseif button_state2 == get(hObject,'Min')
%display('up');
end
Here is the code for the update buttons:
% --- Executes on button press in minusButton.
function minusButton_Callback(hObject, eventdata, handles)
% hObject handle to minusButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.bias = handles.bias-1;
set(handles.zoomText, 'String', num2str(handles.bias));
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in plusButton.
function plusButton_Callback(hObject, eventdata, handles)
% hObject handle to plusButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.bias = handles.bias+1;
set(handles.zoomText, 'String', num2str(handles.bias));
% Update handles structure
guidata(hObject, handles);
Please let me know if I need to post other details, this is my first time posting.
Thanks, Richard
  1 Comment
José-Luis
José-Luis on 15 Jul 2014
Edited: José-Luis on 15 Jul 2014
Would something like evalin() work? You can pass data to the caller that way.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 16 Jul 2014
Unless special actions are taken, all variables in a function are local. You can make the variables global by declaring them global. Functions where the variable is declared global will see it and other functions won't see it. Other options for sharing variables are shown in the FAQ: http://matlab.wikia.com/wiki/FAQ?title=FAQ&cb=2205#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!