How to interact my script with my gui?

10 views (last 30 days)
Robson  Bertazzo
Robson Bertazzo on 18 Apr 2015
Edited: lis coffey on 4 Oct 2016
Hi, i am new to matlab and i have some problems on my project. i want to know how i can call a gui from my script to interact with the values that i got from the script.
Here is my main script.
clear
clc
limiar=0.9;
N_FRAMES_BG = 19;
numero_quadros = 0;
tempo_processamento = 0;
tol=0.2;
a=imread('ref-01.jpg');
b=rgb2gray(a);
c=im2bw(b,limiar);
d=c(1:286,200:420);
g=mean2(d);
for i=2:N_FRAMES_BG,
tic;
IMAGE_NAME=sprintf('ref-0');
frame=imread(strcat(IMAGE_NAME,num2str(i),'.jpg'));
frameg=rgb2gray(frame);
framec=frameg(1:286,200:420);
frameb=im2bw(framec,limiar);
framef=imfill(frameb,'holes');
h=mean2(framef)
if (h>g+tol)
disp('A vaga está ocupada')
Aux=1
else
disp('A vaga está livre')
Aux=0
end
drawnow
refresh
subplot(1,2,1), imshow(d);
subplot(1,2,2), imshow(framef);
pause(0.5);
numero_quadros = numero_quadros + 1;
tempo_processamento = tempo_processamento + toc;
quadros_por_segundo = numero_quadros/tempo_processamento;
end
And the main question is: How i can make a gui interact with my Aux variable to show an image when it's one and another when it's zero. I am making the gui right now, but my concern is how to interact with my loop.
thanks for any help. :)
  1 Comment
lis coffey
lis coffey on 4 Oct 2016
Edited: lis coffey on 4 Oct 2016
i can call a gui from my script to interact with my Aux variable after i ran thru the above writing. thanks

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 18 Apr 2015
Robson - does (or can) the GUI start the script (through a push button callback) or is it the other way around or must they run independently of each other?
If you are creating your GUI with GUIDE (and even if you're not, you can do something similar), then let's assume that your GUI is named/tagged as MyGui. In the GUIDE Property Inspector for MyGui, set the HandleVisibility property to on, and the Tag property to MyGui. This will allow us to search for the GUI given its (unique) tag. Save the changes.
Now in your script, you can pass the Aux value to the GUI as follows
% your script code
if (h>g+tol)
disp('A vaga está ocupada')
Aux=1
else
disp('A vaga está livre')
Aux=0
end
% get the handle of MyGui
hGui = findobj('Tag','MyGui');
% if exists (not empty)
if ~isempty(hGui)
% get handles and other user-defined data associated to MyGui
myGuiData = guidata(hGui);
% set the image of the GUI to be image 0 or 1
if Aux == 0
imshow(myImage0, 'Parent', myGuiData.axes1);
else
imshow(myImage1, 'Parent', myGuiData.axes1);
end
end
The above code assumes that it is the responsibility of the script to tell the GUI which image to display. (It also assumes that the image will be displayed in the control axes1 of the GUI.)
Perhaps the above will be helpful. If you are trying to go the other way, i.e. have the GUI call into the script then you will need to find an alternative approach.

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!