필터 지우기
필터 지우기

Matlab for loops output

조회 수: 2 (최근 30일)
Anum Ahmed
Anum Ahmed 2018년 7월 6일
댓글: Anum Ahmed 2018년 7월 6일
Dear all, I am trying to solve the following loops in MATLAB.
N=4;
d=0.0019;
fc=77e9;
c=3e8;
tdr1=5.33e-7;
Sig = zeros(10:4);
for i=1:N
for AzAng_1 = -90:20:90
Delay_Apos = d*sind(AzAng_1)*((N+1)/2-i)/(c);
Delay_Apos = tdr1 + Delay_Apos;
Steer_Vec = exp(-1i*2*pi*fc*Delay_Apos);
Sig(:,i) = Steer_Vec;
end
i=i+1;
end
Sig
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
At the output, I want to have a matrix of order [10:4] with each row containing the output of 'inner for loop' having a specific value of i. I.e, First column (i=1) should have 10 different values of the 'inner for loop'. After these 10 inner iterations, i value should be updated and now with i=2, inner for loop should be solved and now, the 10 values of 'inner for loop' should be arranged in the 2 column of 'Sig'.
I am trying to solve it, but I only get the last output i.e a (1:4) order signal instead of a (10:4) Signal I need.
I have been working on it, but am unable to get the output I want. Help would be appreciated
Regards

채택된 답변

dpb
dpb 2018년 7월 6일
편집: dpb 2018년 7월 6일
In Sig(:,i) = Steer_Vec; you have the indices reversed relative to the way you sized the array ---
ERRATUM: Bad eyes... :(
Actually, you didn't compute the Delay_Apos as a vector...
...
AzAng_1 = -90:20:90;
for i=1:N
Delay_Apos = d*sind(AzAng_1)*((N+1)/2-i)/(c);
Delay_Apos = tdr1 + Delay_Apos;
Steer_Vec = exp(-1i*2*pi*fc*Delay_Apos);
Sig(:,i) = Steer_Vec;
end
with a loop over i
With meshgrid and recasting the formulae for vector operation you could remove the loop entirely.
  댓글 수: 4
dpb
dpb 2018년 7월 6일
No problem, sorry I got my eyes crossed first go...as noted it can be even more succinct using the ML vector notation. As per usual, one trades some memory for holding temporaries for more efficient code.
K=1i*2*pi*fc; % define a group constant for convenience
% write functions as anonymous -- kept same factoring here..
% NB: dot operators to operate on element basis over arrays
fnDelay = @(ang,idx) tdr1 + d*sind(ang).*((N+1)/2-idx)/c;
fnVec = @(dly) exp(-K*dly);
AzAng = -90:20:90;
[a,ix]=meshgrid(AzAng,1:N); % generate the grid points
Sig=fnVec(fnDelay(a,ix)).'; % and evaluate...
Anum Ahmed
Anum Ahmed 2018년 7월 6일
Thankyou so much for your kind suggestion. Much appreciated.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by