dear all, i am trying to execute this code, but getting the error of "Error using vertcat Dimensions of matrices being concatenated are not consistent"... code is given below, please help me out.
1 view (last 30 days)
Show older comments
Engineer afaque Manzoor soomro
on 10 Jun 2014
Commented: Dishant Arora
on 13 Jun 2014
%program code
% in this programe a highly scattered enviroment is considered. The % Capacity of a MIMO channel with nt transmit antenna and nr recieve % antenna is analyzed. The power in parallel channel (after % decomposition) is distributed as water-filling algorithm
% the pdf of the matrix lanada elements is depicted too.
clear all close all clc
nt_V = [1 2 3 2 4 5 6 7 8]; nr_V = [1 2 2 3 4 5 6 7 8];
N0 = 1e-4; B = 1; Iteration = 1e4; % must be grater than 1e2
SNR_V_db = [-10:3:20]; SNR_V = 10.^(SNR_V_db/10);
color = ['b';'r';'g';'k';'c';'p';'o','d','g']; notation = ['-o';'->';'<-';'-^';'-s';'@';'#';'$';'%'];
for(k = 1 : 9) nt = nt_V(k); nr = nr_V(k); for(i = 1 : length(SNR_V)) Pt = N0 * SNR_V(i); for(j = 1 : Iteration) H = random('rayleigh',1,nr,nt); [S, V, D] = svd(H); landas(:,j) = diag(V); [Capacity(i,j), PowerAllo] = WaterFilling_alg(Pt,landas(:,j),B,N0); end end
f1 = figure(1);
hold on
plot(SNR_V_db,mean(Capacity'),notation(k,:),'color',color(k,:))
f2 = figure(2);
hold on
[y,x] = hist(reshape(landas,[1,min(nt,nr)*Iteration]),100);
plot(x,y/Iteration,'color',color(k,:));
clear landas
end
f1 = figure(1);
legend_str = []; for( i = 1 : length(nt_V)) legend_str =[ legend_str ;... {['nt = ',num2str(nt_V(i)),' , nr = ',num2str(nr_V(i))]}]; end legend(legend_str) grid on set(f1,'color',[1 1 1]) xlabel('SNR in dB') ylabel('Capacity bits/s/Hz')
f2 = figure(2); legend(legend_str) grid on set(f2,'color',[1 1 1]) ylabel('pdf of elements in matrix landa in svd decomposition of marix H')
this is the code for self made function
function [Capacity PowerAllo] = WaterFilling_alg(PtotA,ChA,B,N0); % % WaterFilling in Optimising the Capacity %=============== % Initialization %=============== ChA = ChA + eps; NA = length(ChA); % the number of subchannels allocated to
H = ChA.^2/(B*N0); % the parameter relate to SNR in subchannels % assign the power to subchannel PowerAllo = (PtotA + sum(1./H))/NA - 1./H; while(length(find(PowerAllo < 0 ))>0) IndexN = find(PowerAllo <= 0 ); IndexP = find(PowerAllo > 0); MP = length(IndexP); PowerAllo(IndexN) = 0; ChAT = ChA(IndexP); HT = ChAT.^2/(B*N0); PowerAlloT = (PtotA + sum(1./HT))/MP - 1./HT; PowerAllo(IndexP) = PowerAlloT; end PowerAllo = PowerAllo.'; Capacity = sum(log2(1+ PowerAllo.' .* H));
1 Comment
Sathish Kumar
on 10 Jun 2014
The notation vector you have defined(notation = ['-o';'->';'<-';'-^';'-s';'@';'#';'$';'%'];) is the cause of the error. Each character is one size. The top five row has 2 characters. The sixth row and others have only one character. You have two choices. 1) Add a space to '@' (ie ' @') and others(6-9) inside the quotes. This is just tricking matlab to think that they all have same width. Better and modern way to do is to use cells. eg: notation = {'-o';'->';'<-';'-^';'-s';'@';'#';'$';'%'}; (Note the curly brackets. You can access them using cell2mat and indices. (eg: cell2mat(notation(4)) etc).
Accepted Answer
Dishant Arora
on 10 Jun 2014
dbstop if error
type the above said command at the command prompt before running the script, it'll you to the part of code where exactly this error occurs. Also keep track of workspace to debug.
0 Comments
More Answers (1)
Engineer afaque Manzoor soomro
on 12 Jun 2014
1 Comment
Dishant Arora
on 13 Jun 2014
Make your code readable first http://www.mathworks.in/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup. And post the full error code so that we can help you out.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!