Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab if/elseif命令工作不正常_Matlab - Fatal编程技术网

Matlab if/elseif命令工作不正常

Matlab if/elseif命令工作不正常,matlab,Matlab,亲爱的社区: 我已经经历了你一次又一次的帮助,我再次来到这里寻求帮助 到目前为止,我有一个包含“客户”的模拟器。我想通过分配不同的客户类型(作为属性)对它们进行分类。在某种程度上,这个任务运行得很好,但不知何故,我的代码中仍然有一个bug。但你自己看看: 主要功能 每个客户都有一个名为“id”的属性(客户1有id 1->谁会猜到?) 类客户 问题是您在ceil(ncust/2) /P>我无意冒犯任何人,我当然不认为我可以侮辱自己。不过,我会相应地编辑我的帖子:)谢谢你的提示!没问题,我会删除上面

亲爱的社区:

我已经经历了你一次又一次的帮助,我再次来到这里寻求帮助

到目前为止,我有一个包含“客户”的模拟器。我想通过分配不同的客户类型(作为属性)对它们进行分类。在某种程度上,这个任务运行得很好,但不知何故,我的代码中仍然有一个bug。但你自己看看:

主要功能 每个客户都有一个名为“id”的属性(客户1有id 1->谁会猜到?)

类客户
问题是您在
ceil(ncust/2)
中使用了“or”语句,因此,由于
ceil(ncust/2)
对象id超过一半的所有对象都将是类型2。使用and语句,您将得到所需的结果

e、 g


<> >代码> CELL(NCUST/2)< O.ID.O.O.ID ID CEIL(0.75 *NCUST)< /代码> /P>我无意冒犯任何人,我当然不认为我可以侮辱自己。不过,我会相应地编辑我的帖子:)谢谢你的提示!没问题,我会删除上面的评论,这样其他人就不必知道:)效果很好!谢谢:)
ncust = 500 %//(number of customers)

%function call

for ii = 1:ncust;
    customers{ii} = Customer(ii);
    customers{ii}.setcustTypeDistrib(ncust);
end
function obj = setcustTypeDistrib(obj, ncust) %sets types of customers
    if obj.id < ceil(ncust/2) % 50 percent of the customers are type 1
        obj.custType = 1;

    elseif ceil(ncust/2) < obj.id || obj.id < ceil(0.75*ncust)
        obj.custType = 2;

    elseif ceil(0.76*ncust) < obj.id 
        obj.custType = 3;
    end
end
id: 490
custType: 2
minInterval: 4.7846e+04