How can i rectify this error "Subscripted assignment dimension mismatch."
조회 수: 2 (최근 30일)
이전 댓글 표시
clc
clear all
nCP = 8; %round(Tcp/Ts);
nFFT = 64;
NT = nFFT + nCP;
F = dftmtx(nFFT)/sqrt(nFFT);
MC = 1500;
EsNodB = 0:5:40;
snr = 10.^(EsNodB/10);
beta = 17/9;
M = 16;
modObj = modem.qammod(M);
demodObj = modem.qamdemod(M);
L = 5;
N=5;
ChEstLS = zeros(1,length(EsNodB));
for ii = 1:length(EsNodB)
disp('EsN0dB is :'); disp(EsNodB(ii)); tic;
ChMSE_SVD=0;
g2 = randn(L,N)+1i*randn(L,N);
g = g2/norm(g2);
H = fft(g,nFFT);
X = randi([0 M-1],nFFT,5); %BPSK symbols
XD = modulate(modObj,X)/sqrt(10); % normalizing symbol power
Y = randi([0 M-1],nFFT,5); %BPSK symbols
HhatLS = Y./XD;
Rhh = H*H';
[U,S,V] = svd(Rhh);
p=8;
for k= 1:p-1;
lambdak=diag(S)
delk= lambdak/(lambdak+(beta/snr(ii)));
HhatSVD =U*delk*V*HhatLS;
%syms k
ChMSE_SVD= ChMSE_SVD + ((H -HhatSVD)'*(H-HhatSVD))/nFFT;
end
% for j=1:ii
% ChMSE_SVD=ChMSE_SVD1(:,j);
ChEstSVD(ii)=ChMSE_SVD/MC; % in this line i get an error
%end
toc;
end
% Channel estimation
semilogy(EsNodB,ChMSE_SVD,'b','LineWidth',2);
legend('SVD');
댓글 수: 2
답변 (1개)
Walter Roberson
2018년 3월 30일
You have
ChEstSVD(ii)=ChMSE_SVD/MC; % in this line i get an error
The right hand size, ChMSE_SVD, is a 5 x 5 array, and MC is a scalar, so ChMSE_SVD/MC will give a 5 x 5 result. You are attempting to store that 5 x 5 result into the single location ChEstSVD(ii)
댓글 수: 5
Walter Roberson
2018년 3월 30일
Well, you can use
ChEstSVD(ii,:,:)=ChMSE_SVD/MC;
That will give you a length(EsNodB) by L by N matrix (9 x 5 x 5) to be plotted against X coordinates EsNodB (1 x 9). But now what?
Especially since all of those values are complex ? You are trying to plot the results of a SVD-type computation, but SVD-type calculations do not give scalar outputs (at best you can get a diagonal vector output, if you call svd() and take the second output.)
I also have to ask whether you are aware that when you compute
delk= lambdak/(lambdak+(beta/snr(ii)))
that because lambdak is a vector, you are doing algebraic matrix operations, with the 64 x 1 vector lambdak resulting in a 64 x 64 operation being returned as a least-squared fit because of the / fitting operation. The / operation is not an element-by-element division operator! And if you were to change the / to ./ to get element-by-element division then the U*delk*V operation that follows would fail. So maybe you do want the / operator -- but if so then I would recommend adding a comment describing the meaning of the line.
You might use abs() to convert the 9 x 5 x 5 array ChEstSVD to real values, but that would still leave you with the question of what it means to plot that.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!