2 views (last 30 days)

Show older comments

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')

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.

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.

Adamu Halilu Jabire
on 29 Sep 2019

Walter Roberson
on 16 Feb 2020

Kolangiammal S
on 3 Feb 2020

Walter Roberson
on 4 Feb 2020

You should ask a new Question on this topic.

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

Start Hunting!