How to plot my "real-time" graphic in GUI?

5 views (last 30 days)
Lucas Borba
Lucas Borba on 3 Sep 2020
Edited: Adam Danz on 7 Sep 2020
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?

Answers (1)

Adam Danz
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
Lucas Borba
Lucas Borba on 4 Sep 2020
I want to use this function PlotRealTime inside the function that is in the image below, so when i press the button "Start" the graphic will run this function.
This graphic "axes1" will show me the PloRealTime graphic
Adam Danz
Adam Danz on 4 Sep 2020
Edited: Adam Danz on 7 Sep 2020
Ok. Is there a question you have?
You can either put the code inside that callback function or, if you need that function for other reasons outside of the GUI, you can make it an independent function and include the axis handle in the inputs.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!