필터 지우기
필터 지우기

I want to sum datas that incoming from the sensor, how can I do that?

조회 수: 1 (최근 30일)
Muhammed
Muhammed 2023년 3월 31일
댓글: Muhammed 2023년 4월 3일
I want to continuously sum the temperature values from a sensor.

답변 (1개)

Sivapriya Srinivasan
Sivapriya Srinivasan 2023년 3월 31일
To continuously sum the temperature values from a sensor in MATLAB, you can use a loop to read the sensor values and add them to a running total. Here's an example code snippet that demonstrates this:
total = 0; % initialize the running total to zero
while true % loop indefinitely
% read the temperature value from the sensor
temperature = readTemperature(); % replace with your own function to read the sensor
% add the temperature value to the running total
total = total + temperature;
% display the current total
disp(['Current total: ' num2str(total)]);
% wait for some time before reading the sensor again
pause(1); % replace with your desired time interval
end
In this code, the total variable is initialized to zero. The loop then reads the temperature value from the sensor using the readTemperature() function (which you would need to replace with your own function to read the sensor). The temperature value is added to the running total using the + operator. The current total is then displayed using the disp() function. Finally, the loop waits for some time (in this case, 1 second) before reading the sensor again.
  댓글 수: 4
Walter Roberson
Walter Roberson 2023년 4월 3일
That code is equivalent to
function y = fcn(u);
y = double(u);
end
Are you sure you want to do that? And not, for example, keep a running total of the input values?
Muhammed
Muhammed 2023년 4월 3일
I get Rpm values from Inverter of Vehicle. I try to calculate total km of vehicle according to RPM values.
I am trying to find the total km by constantly adding the km values that I have calculated.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by