Display real time data in GUI.
Show older comments
Hi, I am trying display real time data in GUI,But unable to do it. My code is:
function varargout = voltage(varargin)
% VOLTAGE MATLAB code for voltage.fig
% VOLTAGE, by itself, creates a new VOLTAGE or raises the existing
% singleton*.
%
% H = VOLTAGE returns the handle to a new VOLTAGE or the handle to
% the existing singleton*.
%
% VOLTAGE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in VOLTAGE.M with the given input arguments.
%
% VOLTAGE('Property','Value',...) creates a new VOLTAGE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before voltage_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to voltage_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 voltage
% Last Modified by GUIDE v2.5 19-Nov-2019 09:28:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @voltage_OpeningFcn, ...
'gui_OutputFcn', @voltage_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 voltage is made visible.
function voltage_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 voltage (see VARARGIN)
% Choose default command line output for voltage
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes voltage wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = voltage_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;
clear all
delete(instrfind)
global s
s=serial('COM7','BaudRate',9600,'Terminator','CR');
fopen(s);
% --- Executes on button press in voltage.
function START_Callback(hObject, eventdata, handles)
% hObject handle to voltage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
counter=1;
while 1
data=str2double(char(fread(s, 5).'));
data1=data/1000;
data2(counter)=data1
counter=counter+1;
plot(data2)
drawnow
end
And getting error like:
Undefined function or variable 's'.
Error in voltage>voltage_Callback (line 88)
data=str2double(char(fread(s, 5).'));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in voltage (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)voltage('voltage_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Accepted Answer
More Answers (0)
Categories
Find more on Workspace Variables and MAT Files 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!