0
votes

I'm trying to implement the MUSIC algorithm and I chose Julia to write my code.

DOA=ones(1,rand(1:10))
 for i in 1:length(DOA)
    DOA[1,i]=rand(0:1000)*pi/180;
 end
 sensors=11;
 freq=ones(1,length(DOA[1,:]))
 for i in 1:length(DOA)
   freq[1,i]=rand()*pi*100;
 end
 signals=length(DOA);
 lambda=100;
 dist=lambda/2;
 A=zeros(signals,sensors);
 snr1=rand(20:40);
 N=200;
 x=zeros(length(freq),N);
 for j = 1:length(freq), for k = 1:signals
    x[j,k]=2*exp(im*freq[j]*k);
 end
 for l = 1:signals, for m = 1:sensors
    A[l,m]=exp(-im*2*pi*dist*sin(DOA[1,l])*m/lambda));
 end

So for j = 1:length(freq), for k = 1:signals shows no error but the one after, for l = 1:signals, for m = 1:sensors, keeps showing the 'invalid iteration specification' error.
My novice tries include, commenting the for loop, deleting it completely and giving spaces in between just to see what was going on. Surprisingly, even after I saved the file numerous times and started a new bash session it showed me the same error for a commented for loop and blank spaces. Any ideas about tackling this problem? Or better yet, what can cause such errors? I've attached a screenshot too for the specifics, line 38 being the for loop with the error.

I've attached a screenshot too for the specifics, line 38 being the for loop with the error.

1

1 Answers

1
votes

You can either use one multidimensional for loop using commas, e.g.,

for i = a:b, j = c:d
    ... 
end

or multiple separate for loops without commas, e.g.,

for i = a:b 
    for j = c:d
        ... 
    end
end

Note that within a comprehension, these forms are different

julia> [(i,j) for i = 1:2 for j = 4:5]
4-element Array{Tuple{Int64,Int64},1}:
(1, 4)
(1, 5)
(2, 4)
(2, 5)

julia> [(i,j) for i = 1:2, j = 4:5]
2×2 Array{Tuple{Int64,Int64},2}:
(1, 4)  (1, 5)
(2, 4)  (2, 5)