【发布时间】:2017-02-18 19:15:46
【问题描述】:
如您所见(excel 文件),我想在 Octave 中使用该公式来获得所需的结果。我还上传了八度代码图片和工作区图片。在工作区中,我的存储变量的结果/值应该与 excel(存储列)中的值相同。我怀疑在代码中使用的最后一部分(带有 i-1 的 if 语句似乎是错误)。
有人可以帮我弄清楚吗?让我知道是否需要进一步澄清。我也在下面发布我的代码:
BM_max = 1236;
virtual_feed_max = 64;
operation = dlmread ('2020Operation.csv');
BM = ones (size (operation, 1), 1);
for i=1:size(operation,1)
if operation(i,1)==1
BM(i,1)=BM_max;
else
BM(i,1)=0;
end
end
virtual_feed = ones(size(operation,1),1);
virtual_feed(:,1) = 64;
storage = ones(size(BM,1),1);
c = ones(size(BM,1),1);
for i=1:size(BM,1)
c=(BM(:,1)-virtual_feed(:,1));
end
for i=1:size(BM,1)
if ((i=1)&& c)<0
storage(:,1)=0;
elseif ((i=1)&& c)>0
storage(:,1)=c;
else
# Issue is below (Taking the value from subsequent row is the problem)
if (c+(storage(i-1,1)))<0
storage(:,1)=0;
elseif (c+(storage(i-1,1)))>0
storage(:,1)=(c+(storage(i-1,1)));
end
end
end
【问题讨论】:
-
我看到的只是一张图片的一个断开的链接。请将您的代码包含为文本、格式正确,而不是图像。
-
我也包含了代码。寻找您的建议
-
首先,
((i=1)&& c)<0似乎是错误的,也许您的意思是((i==1)&& c<0)?如果您将代码格式化为code block 也会更好。 -
((i=1)&& c)
-
((i=1)&&c)<0将变量i设置为1的值,然后执行i和c的逻辑与,它只能是真或假,并且永远不会小于零。 所有用户都可以使用我之前评论中链接中描述的代码块。