Matlab 类属性有以下两个与我的问题相关的限制,
- 依赖属性不能存储值
- 属性的设置器(没有指定属性、访问说明符等的普通属性)无法访问其他属性。
在我的场景中,我需要一种解决方法,它允许我拥有一个也可以存储价值的依赖属性。对另一个属性的依赖仅用于条件语句,而不是用于将其值与其他属性本身一起分配。下面给出的代码片段说明了这种情况,这也是我的 Matlab 不允许的要求。
classdef foo
properties
a
b
end
properties (Dependent = true)
c
end
methods
function this = foo(c_init)
a = 1;
b = 1;
this.c = c_init;
end
function this = set.c(this,value)
if b==1
c = value;
else
c = 1;
end
end
function value = get.c(this)
value = this.c;
end
end
end
以上有什么解决方法吗?