gpt4 book ai didi

matlab - 倍频程/MATLAB : How to compare structs for equality?

转载 作者:太空宇宙 更新时间:2023-11-03 19:07:55 25 4
gpt4 key购买 nike

如何在 Octave(或 matlab)中比较两个结构的相等性?

尝试使用 == 运算符会产生:

binary operator `==' not implemented for `scalar struct' by `scalar struct' operations

最佳答案

使用 isequalisequalwithequalnans 函数。示例代码:

s1.field1 = [1 2 3];
s1.field2 = {2,3,4,{5,6}};
s2 = s1;
isequal(s1,s2) %Returns true (structures match)

s1.field3 = [1 2 nan];
s2.field3 = [1 2 nan];
isequal(s1, s2) %Returns false (NaN ~= NaN)
isequalwithequalnans(s1, s2) %Returns true (NaN == NaN)

s2.field2{end+1}=7;
isequal(s1,s2) %Returns false (different structures)

isequal(s1, 'Some string') %Returns false (different classes)

关于matlab - 倍频程/MATLAB : How to compare structs for equality?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9951828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com