How to plot my "real-time" graphic in GUI?
Mostra commenti meno recenti
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?
Risposte (1)
Adam Danz
il 4 Set 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 Commenti
Lucas Borba
il 4 Set 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.
Categorie
Scopri di più su Graphics Performance in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

