Scilab-For循环,索引不断变化

问题描述 投票:1回答:1

我在Scilab中使用非常简单的for循环遇到麻烦。

max_inventory = 0;

for j=1:120

    S(j) = max_inventory + 1;

    if (S(j)<90) then
        cost(j) = 27;

        elseif (90<=S(j)<=110) then
        cost(j) = 25;

        else
        cost(j) = 22;
    end


    max_inventory = max_inventory + 1;


end

[基本上,我希望S具有索引j。因此,通过120次迭代,将有120个不同的S值。即S_1,S_2,...,S_120。

使用if-else条件,我希望“成本”根据S(j)是什么而具有不同的值。

但是,我不断收到错误:

给定操作数的未定义操作。检查或定义功能%b_3_s用于过载。

我不确定此错误的真正含义。

for-loop scilab
1个回答
0
投票

错误出现在

if (90<=S(j)<=110)

您不能像这样编写此测试。像这样写

if (90<=S(j) && S(j)<=110)
© www.soinside.com 2019 - 2024. All rights reserved.