Random graph showing up on my GUI?

Hello. Can someone please point to me why my GUI background turns into a plot graph while trying to run accelerometer data? Here is the only button it occurs on
% --- Executes on button press in Read.
function Read_Callback(hObject, eventdata, handles)
% hObject handle to Read (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%COMPORT
comPort = '/dev/tty.usbmodemfa131';
%READS SERIAL
[accelerometer.s,serialFlag] = setupSerial(comPort);
calCo = calibrate(accelerometer.s);
%READS DATA
a = 0;
if a == 0
[gx gy gz] = readAcc(accelerometer,calCo);
cla;
r = sqrt((gx^2)+(gy^2)+(gz^2));
r
end
guidata(hObject, handles);

4 comentarios

Amed
Amed el 14 de Feb. de 2013
I will post the entire code if needed
Amed
Amed el 14 de Feb. de 2013
Anyone
Amed
Amed el 14 de Feb. de 2013
help
Amed
Amed el 14 de Feb. de 2013
anything

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 14 de Feb. de 2013

0 votos

Are you sure you didn't place a gigantic axes control behind all your other controls on your GUI? And then somehow (not shown here) you plot something to it? What gets plotted? Is it anything you recognize?

3 comentarios

Amed
Amed el 14 de Feb. de 2013
There is nothing getting plotted. Every time I attempt to read data using that code, my background changes into a plot.. here is the entire code for further analysis
function varargout = iMeasureFIG(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @iMeasureFIG_OpeningFcn, ...
'gui_OutputFcn', @iMeasureFIG_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
% ~~~~~~~~~ OPENING / OUTPUT FUNCTIONS ~~~~~~~~~ %
% --- Executes just before BW2 is made visible.
function iMeasureFIG_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
setappdata(handles.ClosePush, 'Close', 0);
% --- Outputs from this function are returned to the command line.
function varargout = iMeasureFIG_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% ~~~~~~~~~ SERIALPUSH SETUP ~~~~~~~~~ %
function [s,flag] = setupSerial(comPort)
% Initialize the serialpush port communication between Arduino and MATLAB
% The input value is the COMPORT should be changed as per requirement
% We ensure that the arduino is also communicatiing with MATLAB at this
% time. A predefined code on the arduino acknowledges this.
% if setup is complete then the value of setup is returned as 1 else 0
flag = 1;
s = serial(comPort);
set(s,'DataBits', 8 );
set(s,'StopBits', 1 );
set(s,'BaudRate', 9600);
set(s,'Parity', 'none');
fopen(s);
a='b';
while (a ~='a')
a=fread(s,1,'uchar');
end
if (a=='a')
disp('serial read');
end
fprintf(s,'%c','a');
mbox = msgbox('Serial Communication setup.'); uiwait(mbox);
fscanf(s,'%u');
% ~~~~~~~~~ CALIBRATION SETUP ~~~~~~~~~ %
function calCo= calibrate(s)
out.s=s;
calCo.offset=0;
calCo.g=1;
%readpush the raw accelerometer output at three different orientations
mbox = msgbox('Lay accelerometer on a flat surface.', 'Calibration'); uiwait(mbox);
[gx_z gy_z gz_z] = readAcc(out,calCo); %gZ = 1, gX = gY = 0 orientation
mbox = msgbox('Stand accelerometer on edge so that X arrow points up.', 'Calibration'); uiwait(mbox);
[gx_x gy_x gz_x] = readAcc(out,calCo); %gX = 1, gY = gZ = 0 orientation
mbox = msgbox('Stand accelerometer on edge so that Y arrow points up.', 'Calibration'); uiwait(mbox);
[gx_y gy_y gz_y] = readAcc(out,calCo); %gY = 1, gX = gZ = 0 orientation
%calculate offsets for each axis
offsetX = (gx_z + gx_y) / 2;
offsetY = (gy_x + gy_z) / 2;
offsetZ = (gz_x + gz_y) / 2;
%calculate scaling factors
gainX = gx_x - offsetX;
gainY = gy_y - offsetY;
gainZ = gz_z - offsetZ;
calCo.offset = [offsetX offsetY offsetZ];
calCo.g = [gainX gainY gainZ];
mbox = msgbox('Sensor calibration complete'); uiwait(mbox);
% ~~~~~~~~~ READACC SETUP ~~~~~~~~~ %
function [gx gy gz] = readAcc(out,calCo)
%mapping between analog inputs and X,Y,Z axes.
% Xch = 1;
% Ych = 3;
% Zch = 2;
fprintf(out.s,'R');
%readpush voltages from accelerometer and reorder
reordered(1)= fscanf(out.s,'%u');
reordered(2)= fscanf(out.s,'%u');
reordered(3)= fscanf(out.s,'%u');
%determine what offset and gain values to use
offset = calCo.offset;
gain = calCo.g;
accel = (reordered - offset) ./ gain;
%map analog inputs to axes
gx = accel(1);
gy = accel(2);
gz = accel(3);
% ~~~~~~~~~ SERIALPUSH READPUSH ~~~~~~~~~ %
function SerialPush_Callback(hObject, eventdata, handles)
handles.comPort = '/dev/tty.usbmodemfa131';
if (~exist('serialFlag','var'))
[handles.accelerometer.s,handles.serialFlag] = ...
setupSerial(handles.comPort);
end
guidata(hObject, handles);
% ~~~~~~~~~ CALIBRATION ~~~~~~~~~ %
function CalibratePush_Callback(hObject, eventdata, handles)
if(~exist('handles.calCo', 'var'))
handles.calCo = calibrate(handles.accelerometer.s);
end
guidata(hObject, handles);
% ~~~~~~~~~ CLOSEPUSH SERIALPUSH ~~~~~~~~~ %
function ClosePush_Callback(hObject, eventdata, handles)
% hObject handle to ClosePush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
setappdata(handles.ClosePush, 'Close', 1);
clc
clear all
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
close all
clc
disp('Serial Port Closed')
% --- Executes on button press in ReadPush.
function ReadPush_Callback(hObject, eventdata, handles)
% hObject handle to ReadPush (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%COMPORT
comPort = '/dev/tty.usbmodemfa131';
%READS SERIALPUSH
[accelerometer.s,serialFlag] = setupSerial(comPort);
calCo = calibrate(accelerometer.s);
%READS DATA
while getappdata(handles.ClosePush,'Close') == 0
[gx gy gz] = readAcc(accelerometer,calCo);
cla;
r = sqrt((gx^2)+(gy^2)+(gz^2));
gz
end
guidata(hObject, handles);
Amed
Amed el 14 de Feb. de 2013
so lost
Image Analyst
Image Analyst el 14 de Feb. de 2013
I can't run it without the fig file. Upload it and the m-file somewhere and tell us where.

Iniciar sesión para comentar.

Alan Hidalgo
Alan Hidalgo el 25 de En. de 2017

0 votos

Hey Amed, I had the same issue with a realtime plot in which I had to open another Gui. Whenever I opened the other Gui, its background had the realtime plot on it too. I have no idea how to fix this with code, I just edited the second Gui and made a much bigger textbox that would cover up the entire frame of the Gui and it did the trick, the graph is no longer visible where it must not. You should give it a try.

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 14 de Feb. de 2013

Respondida:

el 25 de En. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by