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

标签 matlab octave

如何在 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/

相关文章:

matlab - 相对于 Octave/MATLAB 中的向量值移动矩阵中的行

python - 适合 Python 的傅里叶级数

python - Python 中的特征值

matlab - Matlab 中的感知器训练

c++ - Eigen 等价于矩形矩阵的 Octave/MATLAB mldivide

matlab - 在 Matlab/Octave 中填充折线和水平线之间的区域

matlab - 使用 Octave 音程来映射矢量值

python - matlab cumtrapz 和 scipy.integrate cumtrapz 的不同结果

c - 如何从 MATLAB 运行 C 可执行文件?

algorithm - 自定义函数无法将小数转换为单精度 float