Problem with animated line and GUI

Hello guys, im working with a guide for make 2 graphics in real time with information from bluetooth: - First for orientation information (handles.axes1) - Second for proximity information (handles.axes2)
if true
function pb_start_Callback(hObject, eventdata, handles)
% hObject handle to pb_start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global s
line = animatedline;
muestra=1;
while true
vector_datos=fscanf(s);
datos=strsplit(vec_datos,'/');
orientacion_str=datos{1};
orientacion = str2double(orientacion_str);
distancia=datos{2};
distancia = str2double(distancia);
axis([muestra-10,muestra,0,360])
addpoints(line,muestra,orientacion);
drawnow
muestra=muestra+1;
end
end
end
With my code i can graphic well the orientation in default (handles.axes2) axes, but i write axes(handles.axes1) and it doesnt work. I have tried already the option of animatedline('Parent', handles.axes1) and it doesnt work. My problem is that i need to get the orientation animatedline in axes1 and proximity in axes2, but i dont know where i should write axes(handles.axes1) or axes(handles.axes2).

7 个评论

Do you update your handle in the main figure script?
guidata(figure,handles);
As what i know, by default, handle does not pass to your callback.
i think i dont update my handle... this is my whole program:
if true
function varargout = transmision_en_vivo(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @transmision_en_vivo_OpeningFcn, ...
'gui_OutputFcn', @transmision_en_vivo_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if true
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
if true
function transmision_en_vivo_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = transmision_en_vivo_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pb_bt_Callback(hObject, eventdata, handles)
s =Bluetooth('HC-06',1);
fopen(s);
function transmision_en_vivo_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = transmision_en_vivo_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
end
if true
function pb_bt_Callback(hObject, eventdata, handles)
s = Bluetooth('HC-06',1);
fopen(s);
end
if true
function pb_start_Callback(hObject, eventdata, handles)
% hObject handle to pb_start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global s
line = animatedline;
muestra=1;
while true
vector_datos=fscanf(s);
datos=strsplit(vec_datos,'/');
orientacion_str=datos{1};
orientacion = str2double(orientacion_str);
distancia=datos{2};
distancia = str2double(distancia);
axis([muestra-10,muestra,0,360])
addpoints(line,muestra,orientacion);
drawnow
muestra=muestra+1;
end
end
end
if you can help me for update my handle, and choose a figure 1 for 1st animated line, and figure2 for second animatedline. Thank yoou very much!!
Hi, do you mind to re-arrange your code? It is very difficult for me to know which line is command and which line is not command.
do u think the way to graphic 2 animatedlines in 2 different figures is updating handles? i can search information about it. Im new with guides and its a bit difficut for me :/
No problem. refer to my code, how to specify the axes for plot the animated line.
In your code, there is 'gui_OpeningFcn', @transmision_en_vivo_OpeningFcn, it has updated guidata(hObject, handles).
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)
h = animatedline(handles.axes1);
axis([0 4*pi -1 1])
for x = linspace(0,4*pi,10000)
y = sin(x);
addpoints(h,x,y)
drawnow limitrate
end
To run 2 animatedlines in 2 different axes or 2 different figure?
In your code, you just need to specify the axes in line=animatedline(handles.axes1).
forgot to mention that, it is better to specify the axes for axis([muestra-10,muestra,0,360])
axis(handles.axes1,[muestra-10,muestra,0,360])
i discovered today another way to work, but i think its really the same:
if true
hAnimatedLine(1) = animatedline('Parent',handles.axes6);
hAnimatedLine(2) = animatedline('Parent',handles.axes7);
muestra=1;
while true
vector_datos=fscanf(s);
datos=strsplit(vector_datos,'/');
orientacion_str=datos{1};
orientacion = str2double(orientacion_str);
distancia=datos{2};
distancia = str2double(distancia);
handles.axes6.XLim = [muestra-10 muestra]
handles.axes6.YLim = [0 380]
handles.axes7.XLim = [muestra-10 muestra]
handles.axes7.YLim = [0 350]
addpoints(hAnimatedLine(1),muestra,orientacion);
addpoints(hAnimatedLine(2),muestra,distancia);
drawnow
muestra=muestra+1;
end
end
My project is working now!!! Thank you vey much for ur help!
Do you mind accept my answer if it is working for you?

请先登录,再进行评论。

 采纳的回答

Kevin Chng
Kevin Chng 2018-10-10
编辑:Kevin Chng 2018-10-10
Refer to my code, how to specify the axes for plot the animated line.
In your code, there is ' gui_OpeningFcn', @transmision_en_vivo_OpeningFcn, it has updated guidata(hObject, handles).
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)
h = animatedline(handles.axes1);
axis([0 4*pi -1 1])
for x = linspace(0,4*pi,10000)
y = sin(x);
addpoints(h,x,y)
drawnow limitrate
end
In your code, you just need to specify the axes in line=animatedline(handles.axes1).
forgot to mention that, it is better to specify the axes for axis([muestra-10,muestra,0,360])
axis(handles.axes1,[muestra-10,muestra,0,360])

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Animation 的更多信息

产品

版本

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by