Guide GUI Plot More Data Points

18 views (last 30 days)
(Unknown)
(Unknown) on 15 Feb 2018
Edited: (Unknown) on 15 Feb 2018
Hi,
I created a guide GUI connected to an Arduino Uno board to plot the Fahrenheit, Celsius, and Kelvin readings from my temperature sensor. When I run the GUI it reads the temperature and shows the data onto the command window, however when it goes to graph the data points only show the temperatures between the first and second-time frame.
function varargout = hello(varargin)
% HELLO MATLAB code for hello.fig
% HELLO, by itself, creates a new HELLO or raises the existing
% singleton*.
%
% H = HELLO returns the handle to a new HELLO or the handle to
% the existing singleton*.
%
% HELLO('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HELLO.M with the given input arguments.
%
% HELLO('Property','Value',...) creates a new HELLO or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before hello_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to hello_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 hello
% Last Modified by GUIDE v2.5 14-Feb-2018 23:31:50
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @hello_OpeningFcn, ...
'gui_OutputFcn', @hello_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 hello is made visible.
function hello_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 hello (see VARARGIN)
% Choose default command line output for hello
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes hello wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = hello_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;
global a
a = arduino();
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
i = 0; global a;
for i = 0:5
voltage = readVoltage(a,'A0'); %Read Voltage at analog 0
Temperature_C = (voltage*100) - 50;
Temperature_F = (Temperature_C*1.8) + 32; %Conversion to Fahrenheit
Temperature_K = Temperature_C + 273.15; %Conversion to Kelvin
fprintf('Time Elapsed is %d seconds.\n', round(i));
fprintf('Temperature in the Room is %d Degrees Fahrenheit.\n', round(Temperature_F));
fprintf('Temperature in the Room is %d Degrees Celsius.\n', round(Temperature_C));
fprintf('Temperature in the Room is %d Degrees Kelvin.\n', round(Temperature_K));
Plot_F = [i,Temperature_F]; Plot_C = [i, Temperature_C]; Plot_K = [i, Temperature_K];
plot(handles.axes1,Plot_F,'b--','DisplayName','Degrees Fahrenheit') %Plot Degrees in Fahrenheit
hold(handles.axes1,'on')
plot(handles.axes1,Plot_C,'r--','DisplayName','Degrees Celsius') %Plot Degrees in Celsius
hold(handles.axes1,'on')
plot(handles.axes1,Plot_K,'k--','DisplayName','Degrees Kelvin') %Plot Degrees in Kelvin
grid on; %Turns on grid on in the graph
xlabel('Time in Seconds','FontSize',12); ylabel('Degrees','FontSize',12); %x and y axis labels
legend('show','location','northwest')
title(legend,'Degrees in Room')
set(handles.edit1,'String', num2str(Temperature_F));
set(handles.edit2,'String', num2str(Temperature_K));
set(handles.edit3,'String', num2str(Temperature_C));
Axis = findall(0,'type','axes'); %Axis Properties
axis(Axis,[0 5 0 400]) %Defining the axis
plot(magic(5)); [x,y]=ginput
hold (handles.axes1, 'off')
end
guidata(hObject,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)
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
% set(hObject,'BackgroundColor','white');
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

Answers (0)

Categories

Find more on Graphics Object Properties 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!