Subscript indices must either be real positive integers or logicals.

Subscript indices must either be real positive integers or logical.
Term1=sumnr(X,G,tau,i)/sumdr(X,G,i);
Please help!!

4 Comments

More information needed concerning the variables (especially their type and dimensions) (X,G,tau,i) and the functions involved (sumnr,sumdr).
function [ snr ] = sumnr( X,G,tau,k )
%Inputs G,tau & X matrices and index k; returns SUMi(Xi Gik TAUik)
% Detailed explanation goes here
snr=0;
for i=1:8
snr = snr + X(i)*G(i,k)*tau(i,k);
end
end
function [ sdr ] = sumdr( X,G,k )
%Inputs G & X matrices and index k; returns SUMi(XiGik)
% Detailed explanation goes here
sdr=0;
for i=1:8
sdr = sdr + X(i)*G(i,k);
end
end
and similar function
Term3=(sumnr(X,G,tau,i)-X(i)*G(i,i)*tau(i,i))/(sumdr(X,G,i)-X(i)*G(i,i));
it is working but above is not working
Just use the debugger and look at all your variables and you will have the answer far faster than someone can suggest remotely. The error message is as clear as it can be so just look for the index that does not conform to the expectation.
Use the 'Pause on Errors' option to help locate the error, especially if it is in a loop.
The other most likely cause of an error like this is if you have named variables sumnr or sumdr as these would hide the functions of the same name and Matlab would try to interpret what you think are input arguments to a function as indices into a vector.
Never name variables the same as functions!

Sign in to comment.

Answers (1)

Did you define i before calling this line ?
Term3=(sumnr(X,G,tau,i)-X(i)*G(i,i)*tau(i,i))/(sumdr(X,G,i)-X(i)*G(i,i));
If not, i will be the imaginary number and not a real positive integers as it is said in the error message.

Asked:

on 16 Mar 2018

Commented:

on 16 Mar 2018

Community Treasure Hunt

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

Start Hunting!