Matlab 在24个时间段后,将计数减少1
我试过这个Matlab 在24个时间段后,将计数减少1,matlab,time,Matlab,Time,我试过这个 y = an integer which is updated by another code; %% (i don't find it necessary to write that code here) x = 1:10; %% here i have tried to define a range for i = 24*x %% tried to count at the intervals of 24, with multiples o
y = an integer which is updated by another code; %% (i don't find it necessary to write that code here)
x = 1:10; %% here i have tried to define a range
for i = 24*x %% tried to count at the intervals of 24, with multiples of 24
if y < 12
count = count - 1 ;
end
end
y=由另一个代码更新的整数;%%(我觉得没有必要在这里编写代码)
x=1:10;%%在这里,我试图定义一个范围
对于i=24*x%%,尝试以24的间隔计数,倍数为24
如果y<12
计数=计数-1;
终止
终止
但每次统计后,它都在减少。我希望在
24
的一段时间后将其减少。代码是用MATLAB编写的。我不想使用范围,即x=1:10
您的代码非常不清楚,但我还是要冒险猜测一下:
time = 0;
while time < max_time
if mod(time,24)==0
count = count - 1;
end
end
time=0;
而时间<最大时间
如果mod(时间,24)=0
计数=计数-1;
终止
终止
在您的线路上
for i = 24x
这并不意味着什么,因为x是一个向量,不能隐式乘法。如果你想把x的最大值乘以24,你可以说
for i = 24*x
此外,将向量x与整数12进行比较也没有意义。也许你想打电话给我,比如
if x(i) < 12
因此,如果您希望计数(未声明)下降,您可以执行以下操作:
x = 1:10 % A vector containing values from 1 to 10
for i = 24*x % i will be 24, 48, 72, etc.
if x(i) < 12
count = count - 1
pause(24)
end
end
x=1:10%包含1到10个值的向量
对于i=24*x%,我将是24、48、72等。
如果x(i)<12
计数=计数-1
暂停(24)
终止
终止
希望有帮助
x
是表示时间的变量吗?你的意思是代码中的24*x
?@anu现在的y
是什么?投票以“不清楚”结束,直到你提供更好的解释。你想做什么?我很肯定你可以跳过这个循环。你能提供一些背景吗?是的,正如丹所问:什么是x
,i
和y
?环路内部发生了什么?y
更新了吗?好吧,我错了,我没有写完整的代码。对此我深表歉意。但是如果我不想指定任何范围,比如(x=1:10),我们可以不描述任何范围而写吗range@anu不如使用while
循环,如ni my edit。但是,你的问题也特别不清楚。请仔细阅读@Dan请查看我的编辑question@Anu你的更新毫无意义,没有添加任何内容。我们不是巫师或通灵者。如果你不解释清楚,我们无法确定你想要什么。如果不打算在代码中定义时间段的含义,就不能谈论时间段。如果不打算定义某个变量(y
),则不能只包含该变量。它要么很重要,要么根本不属于这个问题。如果您的全部问题是如何创建增量为24
的范围变量,则x=1:24:24*10
。
x = 1:10 % A vector containing values from 1 to 10
for i = 24*x % i will be 24, 48, 72, etc.
if x(i) < 12
count = count - 1
pause(24)
end
end