Gauge widget with matlab data

Pedro 2023-1-17
最新活动Christopher Stapels 编辑于 2023-1-25

Hi, what would be the best approach to use the gauge widget to display calculated data? I have a channel that displays a value that needs some math applied to it to give a correct value. I have a matlab visualization that converts this value into what I need and plots it. However, i believe a gauge is more appropriate than a plot and it seems the matlab "uigauge" object does not work for thingspeak.
Is there a way for the gauge widget to show my data coming out of the matlab script?
Thanks!
Christopher Stapels
Christopher Stapels 2023-1-19
There is a Gage widget built into thingSpeak. On the channel view, select Add Widget, and choose the gage widget. Select the channel, field, and propoerties of the gage widget and the channel where you want it to be displayed. See the widget help for more info.
Pedro
Pedro 2023-1-19
Hi Christopher, thank you for the feedback. I understand that there is a built in feature for that, but it seems seems like it only works for data from the fields that I publish. I wanted to have a gauge to show the result of a matlab script.
Say if a channel publishes a 0-100 value, but I use matlab to conver it to a value between 5-35. How could I add a gauge for that?
Christopher Stapels
Christopher Stapels 2023-1-19
Are you using desktop MATLAB, or MATLAB analysis/viz in ThingSpeak? Either way, after the conversion, you can write back to a new channel and set the gage to read from that new channel.
You can also write code in MATLAB to generate a gage visualization for you. A polar plot makes a good start.
Pedro
Pedro 2023-1-19
I mean in MATLAB analysis/viz in ThingSpeak. In regular MATLAB I can create a gauge with uigauge with no issues. I just wanted to see if I could do the same in ThingSpeak but it seems like I will have to write to a different channel.
Christopher Stapels
Christopher Stapels 2023-1-19
Most UI elements arent allowed in ThingSpeak due to the interface. I have some fairly medium quality gage code that would work in a MATLAB viz, Ive been meaning to post it on file exchange. Thanks for the push. Would something like this work for you? Its a MATLAB function you can run in ThingSpeak to make a gage in a MATLAB viz
Pedro
Pedro 2023-1-25
Absolutely! Thanks for your help!
Christopher Stapels
Christopher Stapels 2023-1-25 (编辑时间: 2023-1-25)
Im not going to get around to putting this on File exchange becasue its too sloppy of a solution, but if it works for you, here is the silly function I wrote (be careful if you use small numbers, the rounding will kill it).
% Sample call
mygage(475,1,3000,0,1200,1200,1800,1800,2800,25);
function MakeGage = mygage(value, lowRange,highRange,greenLow,greenHigh,yellowLow,yellowHigh,redLow,redHigh,nTicks)
% TODO range cannot be less than 1 due to rounding
fullRange = highRange - lowRange;
greenStart = 230 - (360-80) / fullRange * (greenLow - lowRange);
greenEnd = 230 - (360 - 80) / fullRange * (greenHigh - lowRange);
yellowStart = 230 - (360 - 80) / fullRange*(yellowLow - lowRange);
yellowEnd = 230 -(360 - 80) / fullRange * (yellowHigh - lowRange);
redStart = 230 - (360 - 80) / fullRange * (redLow - lowRange);
redEnd = 230 - (360 - 80) / fullRange * (redHigh - lowRange);
tickMove = fullRange / nTicks;
green = [greenStart:-5:greenEnd];
green = green*2*pi/360;
rgreen = ones(1,size(green,2));
polarplot(green, rgreen,'g','LineWidth',16);
hold on
yellow = yellowStart:-5:yellowEnd;
yellow = yellow*2*pi/360;
ryellow = ones(1,size(yellow,2));
polarplot(yellow, ryellow,'y','LineWidth',16);
red = redStart:-5:redEnd;
red = red*2*pi/360;
rred = ones(1,size(red,2));
polarplot(red, rred,'r','LineWidth',16);
valueAngle = 230 - (360-80) / fullRange * (value - lowRange);
rblack = [0:0.1:1];
black = valueAngle * 2 * pi/360 * ones(1,size(rblack,2));
polarplot(black, rblack,'k','LineWidth',5);
ax = gca;
ax.RTickLabel = [];
ax.RGrid = 'off';
width = 280 / nTicks;
tickHold = 0:width:280;
tickHold = tickHold-50;
tickHold = [tickHold(tickHold>=0),tickHold(tickHold<0)+360];
ax.ThetaTick = tickHold;
%ax.ThetaTick=[0:width:230,310:width:360];
tickLabels = round([highRange:-tickMove:lowRange],0);
shift = round(50 / width);
tickLabels = circshift(tickLabels,-shift);
ax.ThetaTickLabel = tickLabels;
ax.RLim = [0,1.05];
text(265*2*pi/360,0.8,string(value),'fontSize',20);
hold off
end