[英]Reformatting sensor data with Matlab
I have a lot of sensor data sorted into 3 columns, time, sensor name, and sensor value.我有很多传感器数据分为 3 列,时间、传感器名称和传感器值。 Wherein sensor name repeats every row, until it gets to the next sensor.
其中传感器名称每行重复,直到到达下一个传感器。
For example: https://i.stack.imgur.com/H9KKi.png (can't post, not enough rep on this stack exchange)例如: https://i.stack.imgur.com/H9KKi.png (无法发布,在此堆栈交换上没有足够的代表)
I want to reformat the data into separate column variables, lined up with their time stamps.我想将数据重新格式化为单独的列变量,并与它们的时间戳对齐。 What would be the best way to do this?
最好的方法是什么? Preferably using Matlab, Excel, or origin.
最好使用 Matlab、Excel 或 origin。 So column headers of time, sensorA, sensorB, with their values underneath.
因此,时间、传感器A、传感器B的列标题及其下方的值。
Many thanks.非常感谢。
I recommend using the unstack
command.我建议使用
unstack
命令。 In the below I read data into a table and then convert to a more tabular form.在下面,我将数据读入表格,然后转换为更表格的形式。
d = readtable("sensorData.xlsx")
d1 = unstack(d,"Value","Sensor")
d =
15×3 table
Date Sensor Value
____________________ __________ _____
12-May-2020 13:00:00 {'Sens_a'} 64
12-May-2020 14:00:00 {'Sens_a'} 9
12-May-2020 14:59:59 {'Sens_a'} 70
12-May-2020 15:59:59 {'Sens_a'} 74
12-May-2020 13:00:00 {'Sens_b'} 37
12-May-2020 14:00:00 {'Sens_b'} 63
12-May-2020 14:59:59 {'Sens_b'} 47
12-May-2020 15:59:59 {'Sens_b'} 94
12-May-2020 16:59:59 {'Sens_b'} 35
12-May-2020 17:59:59 {'Sens_b'} 86
12-May-2020 18:59:59 {'Sens_b'} 26
12-May-2020 13:00:00 {'Sens_c'} 91
12-May-2020 14:00:00 {'Sens_c'} 4
12-May-2020 14:59:59 {'Sens_D'} 22
12-May-2020 15:59:59 {'Sens_D'} 74
d1 =
7×5 table
Date Sens_D Sens_a Sens_b Sens_c
____________________ ______ ______ ______ ______
12-May-2020 13:00:00 NaN 64 37 91
12-May-2020 14:00:00 NaN 9 63 4
12-May-2020 14:59:59 22 70 47 NaN
12-May-2020 15:59:59 74 74 94 NaN
12-May-2020 16:59:59 NaN NaN 35 NaN
12-May-2020 17:59:59 NaN NaN 86 NaN
12-May-2020 18:59:59 NaN NaN 26 NaN
>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.