How to plot my "real-time" graphic in GUI?
5 views (last 30 days)
Show older comments
Hello everyone, i'm trying to use my code of a "real-time" garphic sensor in GUI, but i don't know how to use the PressButtom function to run this code and plot the graphic in axis that Gui has.
This is my code:
function PlotRealTime()
tic;
% Create arduino object with the add-on library
a = arduino('COM5', 'Uno', 'Libraries', 'Ultrasonic');
% Create ultrasonic object
ultrasonicObj = ultrasonic(a,'D13', 'D12');
% Obtain sensed distance
tf = 200;
to = 1;
x=0;
while (to<tf)
d = readDistance(ultrasonicObj)*100;
x = [x,d];
plot(x)
% axis([0 tf 0 30])
grid on
to = to + 1;
drawnow
end
toc
Can anyone help me how to implement this code on Guide?
0 Comments
Answers (1)
Adam Danz
on 4 Sep 2020
The problem is not clear. Initially it sounds like you're asking for help using a PressButton function but that function isn't in the code you shared.
Is the problem that your data aren't appearing on the axes? If so you probably just need to "hold" the GUI axis, use the axis handle in the plotting function, and specify a marker type. Assiming the GUI axis handle is "ax",
hold(ax, 'on')
grid on
while (to<tf)
d = readDistance(ultrasonicObj)*100;
% x = [x,d];
plot(ax, x, 'o')
to = to + 1;
drawnow
end
If this does not address the problem, you'll need to elaborate and provide all relevant details.
2 Comments
See Also
Categories
Find more on Graphics Performance 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!
