Receive value in Matlab GUI
4 views (last 30 days)
Show older comments
Thanadech Wunapeera
on 24 Apr 2015
Commented: Thanadech Wunapeera
on 26 Apr 2015
Hello I'm working with Matlab GUI using GUIDE about show status from arduino(Ex:degree,current) and I have .m file program in Matlab to calculate and read variables when I press 'Start' button. I want program to receive realtime variables. Is there any way to do to make it work? I already try to get variables but It just give me only first time value. Here is my example of my .m file
function [B1, B2, B3, B4] = LogDataB(arduino)
mode=2;
fopen(arduino);
while mode
fprintf(arduino,'%s',1);
if(mode>=1)
B1=fscanf(arduino,'%d');
B2=fscanf(arduino,'%d');%Bx
B3=fscanf(arduino,'%d');%By
B4=fscanf(arduino,'%d');%Bz
end
mode=mode-1;
end
fclose(arduino);
Any idea please.
Thank you
Math
0 Comments
Accepted Answer
Geoff Hayes
on 25 Apr 2015
Thanadech - presumably the function LogDataB is called from the callback of your start button. Is this the case? Note that your while loop will only ever execute twice since your mode is initialized to two. As well, the results obtained for mode equal to two are overwritten for the case when mode is one. Is this intentional?
If you want this function to be called repeatedly once the start button is pressed, you may need to use a timer. See an example at http://www.mathworks.com/matlabcentral/answers/178682-collecting-a-variable-every-two-minutes which you should be able to adapt for your needs. In your case, the timer callback would call your above function.
2 Comments
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps 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!