指定字符串搜索的列和行
因为我正在使用一个非常复杂的表,在可变位置有令人讨厌的重复值,所以我想在特定的行和列之间进行字符串搜索。
例如:
table={{"header1", "header2", "header3",
"header4"}, {"falsepositive", "falsepositive", "name1",
"falsepositive"}, {"falsepositive", "falsepositive", "name2",
"falsepositive"}, {"falsepositive", "falsepositive",
"falsepositive", "falsepositive"}}
%//TableForm=
header1 header1 header1 header1
falsepositive falsepositive name1 falsepositive
falsepositive falsepositive name2 falsepositive
falsepositive falsepositive falsepositive falsepositive
如何在第三列、第一行到第二行中查找字符串?
我想使用 Which
根据字符串在表中的位置分配值。
例如,
Which[string matched in location one, value, matched in location two, value2]
Because I'm working with a very complex table with nasty repeated values in variable places, I'd like to do a string search between specific rows and columns.
For example:
table={{"header1", "header2", "header3",
"header4"}, {"falsepositive", "falsepositive", "name1",
"falsepositive"}, {"falsepositive", "falsepositive", "name2",
"falsepositive"}, {"falsepositive", "falsepositive",
"falsepositive", "falsepositive"}}
%//TableForm=
header1 header1 header1 header1
falsepositive falsepositive name1 falsepositive
falsepositive falsepositive name2 falsepositive
falsepositive falsepositive falsepositive falsepositive
How do I look for a string, for example, in column three, rows one through two?
I'd like to use Which
to assign values based on a string's location in the table.
E.g.,
Which[string matched in location one, value, matched in location two, value2]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我了解,您想要测试给定的字符串是否位于矩阵的某个子部分中。您可以使用
Part
([[...]]) 和Span
(;;) 选择这些小节,您可以使用它们来指示范围或范围的子样本。测试此小节是否包含您的模式可以由MemberQ
完成,如下所示:这样,您的
Which
语句可能如下所示:As I understand it you want a test whether or not a given string is in a certain subsection of a matrix. You can pick these subsections using
Part
([[...]]) andSpan
(;;), with which you can indicate ranges or subsamples of ranges. Testing whether or not this subsection contains your pattern can be done byMemberQ
, like this:In this way, your
Which
statement could look like this:输出->真
或
输出 -> {{2, 3}}
Output -> True
Or
Output -> {{2, 3}}
也许,如果我理解你的话:
Perhaps, if I understand you: