陷入另一个MATLAB问题。在循环k=1:n_i
内,我正在运行此语句。 d(l)
语句中的if d(l)>= -0.5
返回0
作为其值。它甚至不打印d(l)
,而是提供ans = 0
。
任何帮助将不胜感激。 k = 723且n_i为730,d(k = 723)为-1.52。当我分别打印l为727然后尝试d(727)时,我得到了正确的答案。
我正在尝试的是基本上检查d(k)< -1.5。如果是这样,我正在运行一个循环,直到数组的结尾剩余部分来检查一些d(k)> = -0.5
if d(k)<0
for l=k+1:n_i
if d(l)>= -0.5
d(l)
%p=p+(s-F(l,1)-b+E(l,1));
tot=tot+1;
break;
end
end
答案 0 :(得分:0)
你想这样做吗?:
d=randn(1000,1);
n=length(d);
tot=9; % previous tot=9
for i=1:n
if d(i)>=-0.5
tot=tot+1;
break;
end
end
disp(tot); %displaying 10
或者这个?:
i=(1:1000)';
d=randn(1000,1);
n=length(d);
itot=find(d>=-0.5);
plot(i,d); hold on;
plot(itot,d(itot))
干杯...