How can i store looped data from sensor in a table?

16 ビュー (過去 30 日間)
Alexander
Alexander 2025 年 2 月 25 日 21:42
コメント済み: Alexander 2025 年 2 月 25 日 21:58
In this code im reading sensor data in a loop for a specified ammount in a loop. I am trying to store the data in a table but can for the life of me figure out how to do that. here is what i have so far. Any help would be appriciated, or point me to domcumentation that will help. thank you in advance
while i < MaxDataLeng
i = i + 1;
temperature = readTemperature(bmp);
temp_f = ceil (temperature * (9/5)) +32;
pressure = readPressure(bmp);
Altitude = BalAltFunc (pressure, temp_f);
fprintf ('%d\n',i);
fprintf ('---------------------------------------------------------------------------------------------------\n');
fprintf ('temperature: %d F \n', temp_f);
fprintf ('pressure: %f0.1 hPa \n', pressure);
fprintf ('altitude: %d meters \n', Altitude);
fprintf ('---------------------------------------------------------------------------------------------------\n');
pause(Delay);
C = {'interval', 'temp', 'pressure', 'altitude'; i temp_f pressure Altitude;};
end
end

採用された回答

Walter Roberson
Walter Roberson 約5時間 前
編集済み: Walter Roberson 約5時間 前
Initialize
T = table('Size', [0 4], 'VariableTypes', repmat({'double'},1,4), 'VariableNames', {'interval', 'temp', 'pressure', 'altitude'});
Then in your loop,
C = {i temp_f pressure Altitude};
T(end+1,:) = C;
You will probably want to remove the fprintf() from inside the loop.
  1 件のコメント
Alexander
Alexander 約5時間 前
Awesome! Thank you so much, and i was able to understand how and why.

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by