- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是一个non-scalar structure在Matlab中:
clearvars s
s=struct;
for id=1:3
s(id).wa='nko';
s(id).test='5';
s(id).ad(1,1).treasurehunt='asdf'
s(id).ad(1,2).treasurehunt='as df'
s(id).ad(1,3).treasurehunt='foobar'
s(id).ad(2,1).treasurehunt='trea'
s(id).ad(2,2).treasurehunt='foo bar'
s(id).ad(2,3).treasurehunt='treasure'
s(id).ad(id,4).a=magic(5);
end
是否有一种简单的方法来测试结构 s
是否包含字符串“treasure”,而不必循环遍历每个字段(例如,通过变量的实际内容执行“grep”)?
目的是“快速而简单地”查看结构中是否存在字符串(无论在何处)。换句话说(对于 Linux 用户):我想使用“grep” ' 在 matlab 变量上。
我尝试了arrayfun(@(x) any(strcmp(x, 'treasure')), s)
但没有成功,输出:
ans =
1×3 logical array
0 0 0
最佳答案
一种通用方法(适用于任何结构体数组s
)是使用 struct2cell
将结构体数组转换为元胞数组。 ,测试是否有任何单元格 are equal 的内容到字符串 'treasure'
,并对包含结构的任何单元格递归地重复上述操作。这可以在 while loop 中完成如果找到字符串或没有剩余结构可供递归,则停止。这是作为函数实现的解决方案:
function found = string_hunt(s, str)
c = reshape(struct2cell(s), [], 1);
found = any(cellfun(@(v) isequal(v, str), c));
index = cellfun(@isstruct, c);
while ~found && any(index)
c = cellfun(@(v) {reshape(struct2cell(v), [], 1)}, c(index));
c = vertcat(c{:});
found = any(cellfun(@(c) isequal(c, str), c));
index = cellfun(@isstruct, c);
end
end
并使用您的示例结构s
:
>> string_hunt(s, 'treasure')
ans =
logical
1 % True!
关于matlab - 在非标量结构 matlab 中查找字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45885811/
Perl 中的标量是一个简单的数据单元 标量的值可以是一个整数,浮点数,字符,字符串,段落或者一个完整的网页 范例 : Perl 中标量的使用 #!/usr/bin/perl =pod
This question already has answers here: Querying Spark SQL DataFrame with complex types (3个答案) 2年前关闭
我有一个非常基本的问题,找不到解决方案,因此对于初学者的问题,请提前抱歉。 我有一个包含多个 ID 列和 30 个数字列的数据框。我想用相同的因子乘以这 30 列的所有值。我想保持数据框的其余部分不变
我想使用 UUID 作为标识符,但标准标量 ID 被强制转换为字符串。所以在我使用 ID 类型的任何地方都必须从字符串中解析 uuid。 我想知道是否可以用我自己的实现覆盖 ID 类型?这个标量类型有
我有一个函数数组farr,比如说 import numpy as np farr=np.array([(lambda x, y: x+y) for n in range(5)]) (实际上,函数都是不
请帮助我理解以下片段: my $count = @array; my @copy = @array; my ($first) = @array; (my $copy = $str) =~ s/\\/\
我有一个程序,我一直在玩弄,我偶然发现了这样的东西: unsigned char tmp[4]; ... if (mpu_write_mem(D_1_36, 2, tmp+2)) return
我需要很大的帮助,请查看这段代码: import.math dose =20.0 a = [[[2,3,4],[5,8,9],[12,56,32]] [[25,36,45][21,65,98
我要设计一个类PrimitiveType它作为标量、 vector 、张量等数学实体的抽象类,将它们存储在 std::vector myVector 中。我可以通过它进行迭代。例如,有两个相同大小的
这个问题在这里已经有了答案: int a = 0 and int a(0) differences [duplicate] (7 个答案) 关闭 3 年前。 据我所知在C++中是一个初始化的形式 T
perl 代码如下:问题是我无法读取 sub tweak_server{} 中的 $key .... my $key; my %hash = ( flintstones => [ "C:/Users1
我正在尝试使用 symfony3 连接到数据库,但问题是当我将密码放入parameters.yml 中时,出现此错误: 数据库密码:xx%xxxxx%x You have requested a no
我正在寻找 pd.cut 的等价物,但要寻找标量? 我想这样做: bins = [0, 5, 10, 15, 20, 25, 30, 40, 50, 100, 150] pd.cut(43, bins
到目前为止,我在互联网上找到的唯一帮助是 this blog .我认为这会让我到达那里,但我认为它实际上并没有改变我模块中的值。我做了一个示例来说明我的意思。 package Module; use
我盯着 perl LWP::Protocol.pm 中的这段代码,我不明白循环将如何退出: while ($content = &$collector, length $$content) {
两年来,我正在开发一个库:cyme通过“友好容器”执行 SIMD 计算。我能够达到处理器的最大性能。通常用户定义容器并根据以下语法编写内核(简单示例): for(i...) W[i] = R[i]
我正在开发一个 OpenCL 程序,但每次执行的输出都不同。我认为这与将参数传递给内核有关,因为当我对特定执行的值进行硬编码时,每次执行后的输出都是相似的。 我的内核看起来像这样: __kernel
我想在服务类中返回 JSON 文字 @GraphQLQuery(name = "renderUI", description = "Schema for your form") public Stri
我有一个使用 PDL 的函数.最后一步是点积,因此它返回一个标量。但是,当我尝试打印这个标量时,它显然仍然是一个小玩意,并在屏幕上打印如下: [ [ 3 ] ] 我想知道如何将它转换回常规的 Pe
首先,如果我的问题很简单,我深表歉意。我确实花了很多时间研究它。 我正在尝试在 PySpark 脚本中设置标量 Pandas UDF,如所述 here . 这是我的代码: from pyspark i
我是一名优秀的程序员,十分优秀!