why do I get the error : Index exceeds matrix dimensions?
3 views (last 30 days)
Show older comments
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
Accepted Answer
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)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!