フィルターのクリア

Extract sensorvalues from string with units

4 ビュー (過去 30 日間)
Joey
Joey 2022 年 6 月 28 日
コメント済み: Star Strider 2022 年 6 月 28 日
Hello,
I got some CSV files with sensorvalues in it. I used the command 'readtable' to get the data into a Matlab table. It is now a 1440x2 table. In the first variable of the table is a timestamp that works fine, when i try to plot it. But in the second variable i got this format: {'29.6 °C'}. I know when i want to plot the second variable, i have to seperate the value from the unit and convert the value into a number, because i think it is saved as a string. But i can't find a fitting command. Does anyone has an idea how to seperate the values and how to plot them?
Below is a part of the table so you can get a better understanding of my problem.
Var1 Var2
___________________ ___________
2022-06-17 00:00:00 {'28.1 °C'}
2022-06-17 00:01:00 {'28 °C' }
2022-06-17 00:02:00 {'28 °C' }
2022-06-17 00:03:00 {'28 °C' }
2022-06-17 00:04:00 {'28 °C' }
  2 件のコメント
Joey
Joey 2022 年 6 月 28 日
Thanks a lot, that worked for me!
Best Regards
Joel
Star Strider
Star Strider 2022 年 6 月 28 日
As always, my pleasure!

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

採用された回答

Star Strider
Star Strider 2022 年 6 月 28 日
編集済み: Star Strider 2022 年 6 月 28 日
See the documentation section on Remove Prefix or Suffix Characters From Variables
type('Test 2020 06 28.csv') % Original File
2022-06-17 00:00:00, 28.1 °C 2022-06-17 00:01:00, 28 °C 2022-06-17 00:02:00, 28 °C 2022-06-17 00:03:00, 28 °C 2022-06-17 00:04:00, 28 °C
opts = detectImportOptions('Test 2020 06 28.csv');
opts = setvartype(opts, 'Var2','double');
opts = setvaropts(opts, 'Var2','Suffixes','°C');
T1 = readtable('Test 2020 06 28.csv', opts)
T1 = 5×2 table
Var1 Var2 ___________________ ____ 2022-06-17 00:00:00 28.1 2022-06-17 00:01:00 28 2022-06-17 00:02:00 28 2022-06-17 00:03:00 28 2022-06-17 00:04:00 28
figure
plot(T1{:,1}, T1{:,2})
grid
ylim([27 29]) % Change As Necessary For Your Data
That appears to have imported my test file correctly.
EDIT — (28 Jun 2022 at 17:52)
Forgot the plot initially. Added it now.
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by