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 日

0 投票

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 件のコメント

Anum Ahmed
Anum Ahmed 2018 年 7 月 6 日
By doing so, I just get a 4:1 matrix which is showing the values of last iteration of the inner loop only.
Anum Ahmed
Anum Ahmed 2018 年 7 月 6 日
Awesome... It looks so neat now. Thanks alot...
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 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2018 年 7 月 6 日

コメント済み:

2018 年 7 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by