Info

This question is closed. Reopen it to edit or answer.

save data and use it back in the loop with condition

1 view (last 30 days)
Kugen Raj
Kugen Raj on 3 Apr 2012
Closed: MATLAB Answer Bot on 20 Aug 2021
a=abs(randn(1,100));
for n=1:10
count=0;
for angle=0:360
count=count+1;
Xd=(D*cos(angle*pi/180));
Yd=(D*sin(angle*pi/180));
d1(n,count)= sqrt((Yd-y(n))^2+(Xd-x(n))^2);%distance between destination and sensor for 0 to 360 degree.
k(n,count)=((2*pi)/lambda)*(d1(n,count)); %phase lag for each sensor.
yy(n,count)=(exp(-i*k(n,count))*c(n)*a(n)); %weight multiplication to correct the phase lag.
end
end
Y=sum(yy);
YY=abs(Y);
p=20*log10(YY/max(YY));%normalized power in dB;
in the code above, i am creating an array (a) with random values. then i use the array of data to calculate (yy). i test the (yy) value, if the value of (yy) is better than the previous (yy) value, i will use the current (a) array of data to calculate the (yy) value for the next loop. If not i will use the previous (a) value to calculate the next (yy) value. Now the question is, how can I save the (a) value to use it back for the calculation for the next loop. i mean, how can I use the previous (a) value to calculate the (yy) value for the next loop? And, how can I replace the saved (a) value with another new array of (a) values?

Answers (0)

This question is closed.

Tags

Products

Community Treasure Hunt

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

Start Hunting!