Why is the for loop not updating y matrix??

조회 수: 1 (최근 30일)
Sampath reddy
Sampath reddy 2012년 2월 4일
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!!

답변 (1개)

Walter Roberson
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)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by