Nested for loops for cell array

Hi,
I have a cell RDM {1x10} and every cell contains (512x1024) matrix. Now i have applied the following algorithm on one Matrix which i have to apply on all the matrices of cell.
fft_size = 2^6;
Tr = 10;
Td = 8;
Gr = 4;
Gd = 4;
% offset the threshold by SNR value in dB
offset = 1.4;
for i = Tr+Gr+1:(fft_size/2)-(Gr+Tr)
for j = Td+Gd+1:fft_size-(Gd+Td)
noise_level = zeros(1,1);
for p = i-(Tr+Gr) : i+(Tr+Gr)
for q = j-(Td+Gd) : j+(Td+Gd)
if (abs(i-p) > Gr || abs(j-q) > Gd)
noise_level = noise_level + 10.^(RDM(p,q)/10);
end
end
end
threshold = 10*log10(noise_level/(2*(Td+Gd+1)*2*(Tr+Gr+1)-(Gr*Gd)-1));
threshold = threshold + offset;
CUT = RDM(i,j);
if (CUT < threshold)
RDM(i,j) = 0;
else
RDM(i,j) = 1;
end
end
end
I get error on indexing every time. How can i implement that for all 10 matrices. i tried the following.
for k = length(RDM)
RDM{k} = RDM{k}/max(max(RDM{k}));
for i = Tr+Gr+1:(fft_size/2)-(Gr+Tr)
for j = Td+Gd+1:fft_size-(Gd+Td)
%Create a vector to store noise_level for each iteration on training cells
%noise_level = cell{zeros(1,1)};
% Calculate noise SUM in the area around CUT
for p = i-(Tr+Gr) : i+(Tr+Gr)
for q = j-(Td+Gd) : j+(Td+Gd)
if (abs(i-p) > Gr || abs(j-q) > Gd)
noise_level{k} = noise_level{k} + 10.^(RDM{k}(p,q)/10);
end
end
end
% Calculate threshould from noise average then add the offset
threshold{k} = 10*log10(noise_level{k}/(2*(Td+Gd+1)*2*(Tr+Gr+1)-(Gr*Gd)-1));
threshold{k} = threshold{k} + offset;
CUT{k} = RDM{k}(i,j);
if (CUT{k} < threshold{k})
RDM{k}(i,j) = 0;
else
RDM{k}(i,j) = 1;
end
end
end
end

4 Comments

What is the error?
If you don't need to save noise_level, threshold, CUT after the loop finishes, why not keep them as they are in your original code?
Maybe later on i need to use these values based on analysis. that is why i am try to save all values.
Ok. Does this work?
for k = length(RDM)
RDM{k} = RDM{k}/max(max(RDM{k}));
for i = Tr+Gr+1:(fft_size/2)-(Gr+Tr)
for j = Td+Gd+1:fft_size-(Gd+Td)
%Create a vector to store noise_level for each iteration on training cells
noise_level{k} = zeros(1,1);
% Calculate noise SUM in the area around CUT
for p = i-(Tr+Gr) : i+(Tr+Gr)
for q = j-(Td+Gd) : j+(Td+Gd)
if (abs(i-p) > Gr || abs(j-q) > Gd)
noise_level{k} = noise_level{k} + 10.^(RDM{k}(p,q)/10);
end
end
end
% Calculate threshould from noise average then add the offset
threshold(k) = 10*log10(noise_level{k}/(2*(Td+Gd+1)*2*(Tr+Gr+1)-(Gr*Gd)-1));
threshold(k) = threshold(k) + offset;
CUT(k) = RDM{k}(i,j);
if (CUT(k) < threshold(k))
RDM{k}(i,j) = 0;
else
RDM{k}(i,j) = 1;
end
end
end
end
If not, what's the error you're getting?
ARN
ARN on 25 May 2020
Edited: ARN on 25 May 2020
Running is taking a long time: still no result. Maybe i can ignore the CUT and noise level, not the threshold though

Sign in to comment.

Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Products

Asked:

ARN
on 25 May 2020

Edited:

ARN
on 25 May 2020

Community Treasure Hunt

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

Start Hunting!