Matlab for loops output
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
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...
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!