单元格数组中的组数据
我有以下数据:
Names={A1 A2 B1 B2 C1 C2 C3}
Doserate=(2.2 3.4 6.4 3.4 2.3 4.5 7.5)
Time=(5 7.8 9 3.5 10.2 5.6 7.8)
剂量
和time
的顺序与name
相对应。我想将小组从相同的字母开始,以便可以使用doserate
和时间
对应于该组的计算。 名称
可以变化到更多字母(AZ)或更多数字(例如(A1-A30))。
我该如何分组这些条目?
I have the following data:
Names={A1 A2 B1 B2 C1 C2 C3}
Doserate=(2.2 3.4 6.4 3.4 2.3 4.5 7.5)
Time=(5 7.8 9 3.5 10.2 5.6 7.8)
The order of Doserate
and Time
is such they correspond to Names
. I would like to make groups starting with the same letter so that I can perform calculations using Doserate
and Time
corresponding to that group. Names
can vary to even more letters (A-Z) or more numbers like (A1-A30).
How can I group these entries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用循环提取每个单元格中的第一个字符(您可能还可以使用
cellfun()
),然后调用unique()
提取独特的字符。在我的示例中,它的第三个输出名为c
将是您的组。因此,剂量(C(C == 2))
将返回所有剂量>剂量>条目,其中
名称
以b
开始。You can use a loop to extract the first character in each cell entry (you can probably use
cellfun()
as well) and then a call tounique()
to extract the unique characters. Its third output, namedc
in my example, will be your groups. ThusDoserate(c(c==2))
will return allDoserate
entries whereNames
start withB
.要从名称的开头提取一个或多个字母,您可以使用正则是:
然后,您可以使用
findgroups
对它们进行分组,即
gidx == 2
与之匹配组'B'
(gnames
中的第二个元素)。To extract one or more letters from the start of your names, you can use regex:
Then you can use
findgroups
to group themi.e. now anything where
gidx == 2
matches the group'B'
(2nd element ingnames
).