MATLAB Answers

Index in position 1 exceeds array bounds (must not exceed 995)

2 views (last 30 days)
Adamu Halilu Jabire
Adamu Halilu Jabire on 29 Sep 2019
Commented: Walter Roberson on 16 Feb 2020
I am trying to plot a TARC and CCL of my MIMO antenna but am getting this errors
> TARC
Index in position 1 exceeds array bounds (must not exceed 995).
Error in TARC (line 23)
S12a=10^(S12(j,2)/20);
Below is the code
%%
%'txt'
S11=dlmread('Mode 1 S11.txt','',2,0);
S12=dlmread('Mode 1 S12.txt','',2,0);
S21=dlmread('Mode 1 S21.txt','',2,0);
S22=dlmread('Mode 1 S22.txt','',2,0);
freq=S11(:,1);
theta=0:30:180;
na = length (S11);
n = length (theta);
Ta = zeros (na,n+1);
Ta(:,1) = freq;
Taa(:,1) = freq;
for i = 1 : n
th = theta (i);
for j = 1 : na
% if the value of Aa is read from a .txt file (db), you would need to
% convert it to s2p. format (i.e magnitude) as follows;
S11a=10^(S11(j,2)/20);
S12a=10^(S12(j,2)/20);
S21a=10^(S21(j,2)/20);
S22a=10^(S22(j,2)/20);
Ta(j,i+1) = sqrt(((abs(S11a+S12a.*exp(complex(0,1)*th)))^2 + ...
(abs(S21a+S22a.*exp(1i*th)))^2))/sqrt(2);
Taa(j,i+1) = 20*log10(Ta(j,i+1));% Converting values back to db
% Ta(j,i+1) = sqrt(((abs(Aa(j,2)+Aa(j,6).*exp(complex(0,1)*th)))^2 + ...
% (abs(Aa(j,8)+Aa(j,4).*exp(complex(0,1)*th)))^2))/sqrt(2);
% Taa(j,i+1) = 20*log10(Ta(j,i+1));% Converting values to db
% Ta(:,i+1) = sqrt(((abs(S11(:,2)+S12(:,2)*exp(1i*th(i)))).^2 + ...
% (abs(S21(:,2)+S22(:,2)*exp(1i*th(i)))).^2))/sqrt(2);
end
end
%%
figure()
plot(freq,Taa(:,2),'-k');
hold
plot(freq,Taa(:,3),'-.b');
plot(freq,Taa(:,4),'.r');
plot(freq,Taa(:,5),':c');
plot(freq,Taa(:,6),'--g');
plot(freq,Taa(:,7),'-m');
dlmwrite('7.txt',Taa,'delimiter','\t')

Answers (3)

Walter Roberson
Walter Roberson on 29 Sep 2019
na = length (S11);
length() is defined as 0 if the object has any dimension of size 0, and otherwise length is defined as the largest dimension. If a file had 1000 columns and 995 rows, then its length() would be 1000, and trying to iterate to that row number would be a failure.
You should only use length() with something you know to be empty or scalar or a vector; otherwise you should use size() with the appropriate dimension number.
  2 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 29 Sep 2019
Walter sir comment goes here
"Specify the column offset as 0 (I think it reads the 1 column only), as 0,0 offsets read the first element only."
No, notice the documentation says "starts reading".
Row offset 2 means that it skips two header lines before trying to read numeric data. Column offset 0 means it skips 0 columns out of each line.
There is no problem with those lines, provided that the user really does have exactly two header lines to skip.

Sign in to comment.


Adamu Halilu Jabire
Adamu Halilu Jabire on 29 Sep 2019
Thank you very much mr walter Roberson i got it and the plot is ok
  2 Comments
Walter Roberson
Walter Roberson on 16 Feb 2020
If you had asked a new Question when I had suggested two weeks ago, possibly you would have had a response by now. People are not expecting discussion of that topic in this Question about index out of range.

Sign in to comment.


Kolangiammal  S
Kolangiammal S on 3 Feb 2020
Dear sir, Good evening. I am working in UWB antenna design. In that I need to plot the following plots use MATLAB code...getting S parameter and different parameters from cst tool.if u have any idea kindly share 1.Envelope correlate coefficient 2.channel capacity loss ( CCL) 3.mean effective gain 4.multiplexing efficiency Thanks in advance

Community Treasure Hunt

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

Start Hunting!