【发布时间】:2015-07-17 17:59:29
【问题描述】:
我有一个带有调度程序函数的类,它应该将字符插入到元胞数组中:
classdef timeline < handle
properties
schedule
i
%other properties
end
methods
%other functions
function t = timeline()
%other initializations
t.schedule = cell(1,738);
t.i = 1;
end
function scheduler(t, g, fT)
if nargin == 2
fT = t.i;
end
if strcmp(g,'science')
'science' % eclipse occurs after
for j = (fT+t.sTime+1) : (fT+t.sTime+1+t.eTime)
t.schedule{j} = 'e';
end
elseif strcmp(g,'pass')
'pass' % science occurs 2 hrs after end
for j = (fT) : (fT+t.pTime)
t.schedule{j} = 'p'
end
for j = (fT+t.pTime+121) : (fT+t.pTime+120+t.sTime)
t.schedule{j} = 's';
end
scheduler(t, 'science', fT+t.pTime+120);
end
end
end
end
在命令窗口中,我定义了我的对象t = timeline() 和一个模式g = 'pass',然后调用调度程序t.scheduler(t,g)。
它不会更改 schedule 属性。 if 语句中编写日程表的内容不是我关心的问题。我将输出放在if 语句的每个部分,发现strcmp 返回false 并跳过整个块。所以,我在调度器函数中添加了一个断点,发现由于某种原因g作为另一个timeline对象而不是字符串'pass'传递给函数。这是为什么呢?
【问题讨论】:
标签: matlab class argument-passing