Call from .mat to GUI text
3 次查看(过去 30 天)
显示 更早的评论
Hello, I have a function that counts the objects in an image from a web-cam every 30 minutes. (it's an infinite loop, but i make it stop at three for testing) What I want to do is to display in my GUI text-box and being always updated.
But I don't know how to call the values from the matrix of the counteds objects.
Thank for your help.
CODE:
function CalculaParticulas
vid = videoinput('winvideo', 1,'I420_1280x720');
set(vid,'ReturnedColorSpace','grayscale');
Densidad=1000;
VolumenMAX=pi*1000/(8E18);
VolumenMIN=pi*15.625/(8E18);
Caudal=0.01; %m3/min
i=1;
pause(2);%Dejamos 32 minutos de margen antes de empezar (en segundos)
while (1);
img{i} = getsnapshot(vid);
fname = ['img' num2str(i)];%que nombre le ponemos al archivo
imwrite(img{i}, fname, 'jpg');%guardar el archivo con formato
pause(2);%paramos 3minutos entre foto y análisis
img{i} = imread(['img' num2str(i)]);
% %imshow(img1)% Si queremos ver la imagen original
img2{i}=im2bw(img{i},graythresh(img{i}));
img2{i}=~img2 {i};
B=bwboundaries(img2 {i});
NumberOfParticle(i)=length(B);
% disp(['Hay ', num2str(NumberOfParticle), ' partículas'])
%hold on
%for k = 1:length(B)
%boundary = B{k};
%plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 0.2);
%end
Concentracion(i,1)=NumberOfParticle(i)*VolumenMAX*Densidad/Caudal
Concentracion(i,2)=NumberOfParticle(i)*VolumenMIN*Densidad/Caudal
Concentracion(i,3)=(Concentracion(i,1)+Concentracion(i,2))/2
save('concentracion.mat','Concentracion');
i=i+1;
pause(5); %esperamos 27'
if i==3;
break;
end
end
CODE GUI
function varargout = Interfaz(varargin)
% INTERFAZ MATLAB code for Interfaz.fig
% INTERFAZ, by itself, creates a new INTERFAZ or raises the existing
% singleton*.
%
% H = INTERFAZ returns the handle to a new INTERFAZ or the handle to
% the existing singleton*.
%
% INTERFAZ('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in INTERFAZ.M with the given input arguments.
%
% INTERFAZ('Property','Value',...) creates a new INTERFAZ or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Interfaz_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Interfaz_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Interfaz
% Last Modified by GUIDE v2.5 27-Mar-2014 09:17:01
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Interfaz_OpeningFcn, ...
'gui_OutputFcn', @Interfaz_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Interfaz is made visible.
function Interfaz_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Interfaz (see VARARGIN)
% Choose default command line output for Interfaz
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Interfaz wait for user response (see UIRESUME)
% uiwait(handles.figure1);
load(concentracion);
% --- Outputs from this function are returned to the command line.
function varargout = Interfaz_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes when selected object is changed in uipanel2.
function uipanel2_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uipanel2
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
if (hObject==handles.radiobutton1)
set (handles.text4, 'String', num2str(concentracion(end,3))); %i think it is not correct, but don't know what put here
elseif (hObject==handles.radiobutton2)
set (handles.text4, 'String', num2str(concentracion(end,3)));
end;
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dialog Boxes 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!