从细胞阵列中删除测量单元
我正在尝试将单元从单元阵列数据的一列中删除,即:
cArray =
time temp
2022-05-10 20:19:43 '167 °F'
2022-05-10 20:19:53 '173 °F'
2022-05-10 20:20:03 '177 °F'
...
2022-06-09 20:18:10 '161 °F'
我尝试了str2double,但要获取所有NAN。
我在Regexp上找到了一些信息,但并不完全遵循示例不完全相同。
任何人都可以帮助我获取温度列以仅阅读值,即:
cArray =
time temp
2022-05-10 20:19:43 167
2022-05-10 20:19:53 173
2022-05-10 20:20:03 177
...
2022-06-09 20:18:10 161
I am trying to remove the units out of a column of cell array data i.e.:
cArray =
time temp
2022-05-10 20:19:43 '167 °F'
2022-05-10 20:19:53 '173 °F'
2022-05-10 20:20:03 '177 °F'
...
2022-06-09 20:18:10 '161 °F'
I have tried str2double but get all NaN.
I have found some info on regexp but don't follow exactly as the example is not the same.
Can anyone help me get the temp column to only read the value i.e.:
cArray =
time temp
2022-05-10 20:19:43 167
2022-05-10 20:19:53 173
2022-05-10 20:20:03 177
...
2022-06-09 20:18:10 161
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于某些单元格数据阵列,
最简单的选项是,如果我们可以安全地假设温度数据始终以数字值开头,并且您需要所有数字值。然后,我们可以使用REGEX仅匹配
Match
选项原因REGEXP
以返回匹配字符串而不是匹配索引,而a a a in Code>一旦
意思是“停在第一场比赛中”,这样我们就会忽略第一个非数字角色之后的所有内容。模式
'\ d+'
表示“一个或多个数字”。您可以使用'\ d+(\。\ d+)?
将其扩展到与十进制零件匹配的数字,如果是要求。然后,如果要实际输出数字,则应使用
str2double
。您可以在循环中执行此操作,也可以使用cellfun
,这是实现同一件事的一种紧凑方法。最后,您可以在
Carray
中覆盖列For some cell array of data
The easiest option is if we can safely assume the temperature data always starts with numeric values, and you want all of the numeric values. Then we can use regex to match only numbers
The
match
option causesregexp
to return the matching string rather than the index of the match, andonce
means "stop at the first match" so that we ignore everything after the first non-numeric character.The pattern
'\d+'
means "one or more numbers". You could expand it to match numbers with a decimal part using'\d+(\.\d+)?'
instead if that's a requirement.Then if you want to actually output numbers, you should use
str2double
. You could do this in a loop, or usecellfun
which is a compact way of achieving the same thing.Finally you can override the column in
cArray