How to add waitbar to matlab gui with daq?
Show older comments
Hello everyone,
I'm making a gui to control sending signals through a daq system from ni.
Sending a signal through the system and reciving it back takes time, and im tying to make this time visible through a waitbar.
Now i've looked up some examples on how to use waitbar and how to embedded it with gui, but i didn't learn much and it still complicated to me.
Here is a section of the program:-
%----------------------------------------------------------------------------
addinput(dq, "Dev2", "ai10", "Voltage");
addoutput(dq, "Dev2", "ao0", "Voltage");
TEST =A* chirp(t,x1,t1,x2);
%--------------------
axes(handles.axes1);
ao=TEST.*t
plot(t, ao,'linewidth',2);
grid on
title('Signal im Zeitbereich')
xlabel('t (s)')
ylabel('A (V)')
%----------
setappdata(0 ,'TEST',TEST)
setappdata(0 ,'t',t)
%----------
ao=ao'
data=readwrite(dq,(ao));
axes(handles.axes2);
plot(data.Time, data.Variables,'linewidth',2 )
title('Daten im Zeitbereich')
xlabel('t (s)')
ylabel('A (V)')
grid on
%----------
setappdata(0 ,'Data',data)
%----------
%----------------------------------------------------------------------------
If needed i can also attach the full program.
Regards,
Ali
5 Comments
Rik
on 16 Feb 2022
Also, is there a specific reason you're storing data in the appdata of the groot?
Ali Albaidhani
on 16 Feb 2022
Rik
on 16 Feb 2022
I would suggest re-implementing the waitbar as an axes with a patch. Not as fancy as the built-in bar (for many releases), but it is much easier to work with.
There is no need to share data through the root object like that. You can use the guidata struct to store them in your GUI figure, or use setappdata to set them in one of the other objects. Using the root object has the same downsides as using global variables: they work perfectly, until they don't. And then you spend hours or days debugging code.
Ali Albaidhani
on 16 Feb 2022
Did you read the link I posted? Did you read the documentation for the patch function? If you simply have one side of an axes filled with a color, that looks like a progress bar. There are probably also dozens of progress bars on the file exchange.
As for the data: did you read the link I posted? Did you read the documentation for the guidata function? Or for the setappdata function?
It works fine for now, but once you run a second instance it will cause strange problems. Or if you create a second thing and run both of them at the same time. The fact that it works now is not really related to the whether it is a good idea.
Everybody starts out as a beginner. It is your choice whether you want to stay a beginner. Read the documentation and read the links with long advice threads. They contain a lot of advice.
Answers (0)
Categories
Find more on App Building 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!