why do I get the error : Index exceeds matrix dimensions?

1 view (last 30 days)
hello all! I am trying to do channel estimation using compressive sensing using basis pursuit denoising from spgl in matlab. following is my code segment. but I am constantly getting the error:
Index exceeds matrix dimensions.
Error in partialFourier (line 8)
y = z(idx);
Error in @(x,mode)partialFourier(p,ofdm.N,x,1)
Error in aunt (line 106)
Rb=opA(y(i),1);
I have tried to match the dimensions of both but its not working. can anyone help me please.
%%%%%%%%%%%%%%%%%%code for spg_bpdn%%%%%%%%%%%%%%
ofdm.N=128;
ofdm.PP=13;
ofdm.B=1;
%%Saprse Channel estimation
H_Sparse = zeros(ofdm.N,ofdm.B);
m=50;k=14;
for b = 1 : ofdm.B
p = randperm(ofdm.N); p = p(1:k);
opts = spgSetParms('verbosity',0);
opA= @(x,mode) partialFourier(p,ofdm.N,x,1);
y=zeros(ofdm.N,1);
y(p) = ofdm.N/ofdm.NP *fft(ifft(dataRxFFT(ofdm.PP,1)));
y=y(p);
Rb=opA(y(p),1);
x=spg_bpdn(@(x,mode)opA(x,mode),Rb,0.05,opts);
H_Sparse(:,1)=ofdm.N/ofdm.NP * fft(ifft(vec2mat(x,ofdm.N)));
end
  3 Comments
bena
bena on 28 Aug 2014
Edited: dpb on 28 Aug 2014
I think the issue is with dataRxFFT, I tried to do
fft(ifft(dataRxFFT(ofdm.PP,1)))
but the problem is still there. idx and y have same dimensions when I use the following lines of code:
y(p) = ofdm.N/ofdm.NP *fft(ifft(dataRxFFT(ofdm.PP,1)));
y=y(p);
Rb=opA(y(p),1);
yet, the error remains the same. when I run the same code without dataRxFFT, i.e. by using
y(p)=randn(k,1) + sqrt(-1) * randn(k,1);
the code compiles and correct results are generated. but when I use dataRxFFT I get the error. any ideas??

Sign in to comment.

Accepted Answer

dpb
dpb on 28 Aug 2014
Edited: dpb on 28 Aug 2014
It took a while to puzzle thru what you're doing...I still have absolutely no klew as to why one would do this, but...
The problem in dimension arises by the way you're generating the vector y as
y(p)=...
y=y(p);
then subsequently you then try to refer to y w/ the subscript vector p again.
The assignment of
y=y(p);
turns size(y) into [length(p),1] or, in the example given length(y) is now 14. But, the p index vector is a permutation of a subset of 14 values between 1-128 by
p = randperm(ofdm.N); p = p(1:k);
So, excepting for the one case which will likely never occur, you're trying to reference some non-existent value >14 in y with the subsequent assignment via the index vector p
Don't know what you want for a final output, but that's the problem with your indexing expression as written. OTHO,
Rb=opA(y,1);
will work if you want an input vector of the 14 values only w/o the zero-fill in the original.

More Answers (1)

bena
bena on 29 Aug 2014
this is the working code segment. thankx all!!
%% Saprse Channel estimation H_Sparse = zeros(ofdm.N,ofdm.B); m=50;
for b = 1 : ofdm.B
idx=randperm(ofdm.N);idx=idx(1:m);
p = randperm(ofdm.N); p = p(1:k);%p=p';
opts = spgSetParms('verbosity',0);
%u_fft=zeros(ofdm.N,1);
opA= @(x,mode) partialFourier(idx,ofdm.N,x,mode);
y=zeros(ofdm.N,1);
y(p) =dataRxFFT(ofdm.PP,b);
Rb=opA(y,1);
x=spg_bpdn(@(x,mode)opA(x,mode),Rb,0.05,opts);
H_Sparse(:,1)=ofdm.N/ofdm.NP * fft(ifft(vec2mat(x,ofdm.N)));
end

Community Treasure Hunt

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

Start Hunting!