Borrar filtros
Borrar filtros

Push Button with uicontrol to run figure again

4 visualizaciones (últimos 30 días)
Alex Stoja
Alex Stoja el 18 de Nov. de 2016
Comentada: Jan el 18 de Nov. de 2016
Hi,
I'm trying to add push buttons to my figure. The first is to clear my figure and the second is to run it again. I already git the clear button but struggeling the program the start button.
My program got a rectime of 10 sec. and is live plotting my acceleration with im getting from a sensor. Can someone help me and sorry for my english I'm a native speaker
This is my Code
if true
clear all;
close all;
samplerate = 10; %Hz samples = 100; rectime = samples/samplerate;
% Find a serial port object. obj1 = instrfind('Type', 'serial', 'Port', 'COM3', 'Tag', '');
% Create the serial port object if it does not exist % otherwise use the object that was found. if isempty(obj1) obj1 = serial('COM3'); else fclose(obj1); obj1 = obj1(1); end
% Connect to instrument object, obj1. fopen(obj1);
% Configure instrument object, obj1. set(obj1, 'BaudRate', 115200); set(obj1, 'Terminator', {'LF','LF/CR'});
% Communicating with instrument object, obj1. i=0;
data={};
%uicontrol('Style','pushbutton','String','Start','Callback','uiresume(gcbf)');
btn = uicontrol('Style', 'pushbutton', 'String', 'Clear',...
'Position', [20 20 50 20],...
'Callback', 'cla');
btn = uicontrol('Style', 'pushbutton', 'String', 'Start',...
'Position', [20 0 50 20],...
'Callback', '');
subplot(1,1,1)
title('Acc X')
while (i <7)
fscanf(obj1,'%c');
i = i+1;
end
x_co = 1; t = x_co-1;
while (i < 108)
gyr_box = fscanf(obj1,'%c');
gyr_box_array = strsplit(gyr_box,',');
acc_box = fscanf(obj1,'%c');
acc_box_array = strsplit(acc_box,',');
% ax_c = acc_box_array(2); % ax(x_co) = str2double(ax_c); % ay_c = acc_box_array(3); % ay(x_co) = str2double(ay_c); % az_c = acc_box_array(4); % az(x_co) = str2double(az_c); % gx_c = gyr_box_array(2); % gx(x_co) = str2double(gx_c); % gy_c = gyr_box_array(3); % gy(x_co) = str2double(gy_c); % gz_c = gyr_box_array(4); % gz(x_co) = str2double(gz_c);
ax(x_co) = (str2double(acc_box_array(2))/8192)*9.81;
%figure
drawnow;
subplot(1,1,1)
plot(ax,'r')
title('Acc X')
xlabel('Zeit')
ylabel('Beschleuigung')
data = [data;{acc_box}];
data = [data;{gyr_box}];
%data=[data;{fscanf(obj1,'%c')}];
i=i+1; x_co = x_co+1; t = [t (x_co-1)/10]; end
while (i < samples)
gyr_box = fscanf(obj1,'%c');
gyr_box_array = strsplit(gyr_box,',');
acc_box = fscanf(obj1,'%c');
acc_box_array = strsplit(acc_box,',');
% ax_c = acc_box_array(2); % ax(x_co) = str2double(ax_c); % ay_c = acc_box_array(3); % ay(x_co) = str2double(ay_c); % az_c = acc_box_array(4); % az(x_co) = str2double(az_c); % gx_c = gyr_box_array(2); % gx(x_co) = str2double(gx_c); % gy_c = gyr_box_array(3); % gy(x_co) = str2double(gy_c); % gz_c = gyr_box_array(4); % gz(x_co) = str2double(gz_c); %
ax(x_co) = (str2double(acc_box_array(2))/8192)*9.81;
%figure
drawnow;
subplot(1,1,1)
plot(ax(length(ax)-100:1:length(ax)),'r')
title('Acc X')
xlabel('Zeit')
ylabel('Beschleuigung')
data = [data;{acc_box}];
data = [data;{gyr_box}];
%data=[data;{fscanf(obj1,'%c')}];
i=i+1; x_co = x_co+1; t=[t (x_co-1)/10]; end
save data;
fclose(obj1); % code end
  1 comentario
Jan
Jan el 18 de Nov. de 2016
Please format your code properly using the "{} Code" button. Currently it is not readable. Omit all parts of the code, which do not concern your problem: It is tedious to read so much code only to find out, which part you are talking of.
If you cross-post a problem in different forums, please add links to the other forum. This reduces to waste time by posting an answer, which has been given elsewhere already. Thanks.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by