How to create multiple live updating plots on one script?
Show older comments
We have flowrate, temperature, and pressure sensors that record data and send it to an arduino which then is connected to matlab on our computer. We were able to get live updates of just the flow sensor, but we want to create 3 seperate windows to display all three types of data at once. Here is our code so far
clear
a = arduino; %connecting to arduino
flowrate_archive_a = [];%creating an empty arrary for the final array of flowrate
flowrate_archive_b = [];
flowrate_archive_c = [];
flowrate_archive_d = [];
flowrate_archive_e = [];
flowrate_archive_f = [];
i=1; %counter variable
%pump_count = input("How many Flow Rate Monitors are being Run? Ex:4");
%fprintf("Make sure Pump A is Wired to A0, Pump B into A1, and so on ***Leave every pump plugged in even if not in use***")
%pump_order = input('What order are the pumps being used? Ex: A,C,E,F')
%ax_1 = axes(); %creating the graph
% hold on; %making the graph stay for the entire lenth of run
ylim([0,11])%Setting y Limit
title("Flowrate (5min)")%setting the title
xlabel("Time (s)") %labeling the x axis
ylabel("Flowrate (mL/min)")%labeling the y axis
legend('Pump A','Pump B', 'Pump C', 'Pump D', 'Pump E', 'Pump F')
if readVoltage(a,'A0') ~= 0
voltage_a = readVoltage(a,'A0');%reading voltage from arduino and storing it as a variable
flowrate_archive_a(i) = (voltage_a-0.8077)/0.2876; %converting the voltage to flowrate
line1 = line(i,flowrate_archive_a(i),'Color','red'); %Creating the line for flowrate A
else
line1 = line(i,0)
end
if readVoltage(a, 'A1') > 0.5
voltage_b = readVoltage(a,'A1');%reading voltage from arduino and storing it as a variable
flowrate_archive_b(i) = (voltage_b-0.8077)/0.2876 %converting the voltage to flowrate
line2 = line(i,flowrate_archive_b(i),'Color','#D95319'); %Creating the line for flowrate B
else
line2 = line(i,0)
end
if readVoltage(a, 'A2') ~= 0
voltage_c = readVoltage(a,'A2');%reading voltage from arduino and storing it as a variable
flowrate_archive_c(i) = (voltage_c-0.8077)/0.2876; %converting the voltage to flowrate
line3 = line(i,flowrate_archive_c(i),'Color','#EDB120'); %Creating the line for flowrate C
else
line3 = line(i,0)
end
if readVoltage(a, 'A3') ~= 0
voltage_d = readVoltage(a,'A3');%reading voltage from arduino and storing it as a variable
flowrate_archive_d(i) = (voltage_d-0.8077)/0.2876; %converting the voltage to flowrate
line4 = line(i,flowrate_archive_d(i),'color',"#77AC30"); %Creating the line for flowrate D
else
line4 = line(i,0)
end
if readVoltage(a, 'A4') ~= 0
voltage_e = readVoltage(a,'A4');%reading voltage from arduino and storing it as a variable
flowrate_archive_e(i) = (voltage_e-0.8077)/0.2876; %converting the voltage to flowrate
line5 = line(i,flowrate_archive_e(i),'color','#4DBEEE'); %Creating the line for flowrate E
else
line5 = line(i,0)
end
if readVoltage(a, 'A5') ~= 0
voltage_f = readVoltage(a,'A5');%reading voltage from arduino and storing it as a variable
flowrate_archive_f(i) = (voltage_f-0.8077)/0.2876; %converting the voltage to flowrate
line6 = line(i,flowrate_archive_f(i),'color','m'); %Creating the line for flowrate F
else
line6 = line(i,0)
end
%line2 = line(i,flowrate_archive_b)
i=i+1;%adding to the counter
while(1)
voltage_a = readVoltage(a,'A0');
flowrate_archive_a(i) = (voltage_a-0.8077)/0.2876;
voltage_b = readVoltage(a,'A1');
flowrate_archive_b(i) = (voltage_b-0.8077)/0.2876;
voltage_c = readVoltage(a,'A2');
flowrate_archive_c(i) = (voltage_c-0.8077)/0.2876;
voltage_d = readVoltage(a,'A3');
flowrate_archive_d(i) = (voltage_d-0.8077)/0.2876;
voltage_e = readVoltage(a,'A4');
flowrate_archive_e(i) = (voltage_e-0.8077)/0.2876;
voltage_f = readVoltage(a,'A5');
flowrate_archive_f(i) = (voltage_f-0.8077)/0.2876;
pause(1.0);%waiting for 1 second between samples
if(i<300) %setting max X axis length
line1.XData = [line1.XData i];
line2.XData = [line2.XData i];
line3.XData = [line3.XData i];
line4.XData = [line4.XData i];
line5.XData = [line5.XData i];
line6.XData = [line6.XData i];
else
xlim([i-299,i]) %Limiting x axis length to 300 sec
line1.XData = [line1.XData i];
line2.XData = [line2.XData i];
line3.XData = [line3.XData i];
line4.XData = [line4.XData i];
line5.XData = [line5.XData i];
line6.XData = [line6.XData i];
end
line1.YData = [line1.YData flowrate_archive_a(i)];
line2.YData = [line2.YData flowrate_archive_b(i)];
line3.YData = [line3.YData flowrate_archive_c(i)];
line4.YData = [line4.YData flowrate_archive_d(i)];
line5.YData = [line5.YData flowrate_archive_e(i)];
line6.YData = [line6.YData flowrate_archive_f(i)];
i=i+1;
end
Accepted Answer
More Answers (0)
Categories
Find more on Arduino Hardware 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!