Why is the for loop not updating y matrix??
1 次查看(过去 30 天)
显示 更早的评论
f=10000;
tmax=.01;
t=0:1/f:tmax;
[m n]=size(t);
y=randperm(n);
a=sin(2*pi*400*t);
b=sin(2*pi*400*t+pi/2);
f=a>0;
g=b>0;
pr=circshift(g,[1 n-1]);
subplot(5,1,1);
plot(t,a),grid on;
subplot(5,1,2);
plot(t,b),grid on;
subplot(5,1,3);
plot(t,f),grid on;
subplot(5,1,4);
plot(t,g),grid on;
for i=2:size(t),
if pr(1,i)~=g(1,i)
y(1,i)=xor(f(1,i),pr(1,i));
else
y(1,i)=y(1,i-1);
end
end
subplot(5,1,5);
plot(t,y);
I'm trying to updated y matrix if a condition is satisfied. But it is not happening so. Why?
Could someone help me??
Thank you!!
0 个评论
回答(1 个)
Walter Roberson
2012-2-4
Your line
for i=2:size(t)
is wrong. size(t) returns a vector, and the colon operator does strange things when it is given a vector.
Change the size(t) to length(t)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!