Info

This question is closed. Reopen it to edit or answer.

factor the data displayed in graphs

1 view (last 30 days)
Ameen Mouazzen
Ameen Mouazzen on 24 Apr 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello,
I have this code that displays data from 2 sensors in graphs vs time
dat1 should be substracted from 8411800 and then multiplied by 0.000462214
as follows:
(dat1-8411800)*0.000462214
the brackets are important
how do I add it?
clear
clc
a=arduino('com3','Uno')
loadcell=addon(a,'ExampleAddon/HX711',{'D2','D3'})
plotTitle1 = 'Load VS Time';
xLabel1 = 'Elapsed Time (s)';
yLabel1 = 'Load (KN)';
legend1 = 'Load Cell'
plotTitle2 = 'Displacement VS Time';
xLabel2 = 'Elapsed Time (s)';
yLabel2 = 'Displacement (mm)';
legend2 = 'Displacement Sensor'
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 2 2]);
yMax1 = 10000000
yMin1 = 0
yMax2 = 10000000
yMin2 = 0
plotGrid = 'on';
min1 = 0;
max1 = 1000;
min2 = 0;
max2 = 1000;
delay = .001;
time = 0;
data1 = 0;
data11 = 0;
data12 = 0;
data2 = 0;
data21 = 0;
data22 = 0;
count = 0;
subplot(1,2,1), hold on
subplot(1,2,2), hold on
tic
n = 2000;
[time, data1, data2] = deal( zeros(1,n) );
time(1) = 0;
data1(1) = read_HX711(loadcell)
data2(2) = readVoltage(a,'A0')
for count = 2:n
dat1 = read_HX711(loadcell)
dat2 = readVoltage(a,'A0')*90
time(count) = toc;
data1(count) = dat1(1);
data2(count) = dat2(1);
subplot(1,2,1)
xlabel(xLabel1,'FontSize',15);
ylabel(yLabel1,'FontSize',15);
plot([time(count-1) time(count)], ...
[data1(count-1) data1(count)],'.-b');
subplot(1,2,2)
xlabel(xLabel2,'FontSize',15);
ylabel(yLabel2,'FontSize',15);
plot([time(count-1) time(count)], ...
[data2(count-1) data2(count)],'.-r');
drawnow
pause(delay);
end
subplot(1,2,1), hold off
subplot(1,2,2), hold off
delete(a);
disp('Plot Closed and arduino object has been deleted');

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!