Subscript indices must either be real positive integers or logicals.

I am doing a work for my class and in this equation:
p(f)=(((sum(sin(2*pi*f*(ti-t)))).^2)/(sum(sin(2*pi*f*(ti-t)).^2)))+((sum(cos(2*pi*f*(ti-t)))).^2)/(sum(cos(2*pi*f*(ti-t).^2)));
it gives me this error :
Subscript indices must either be real positive integers or logicals.
ftab3 is a matrix 82x2; ti is a vector 1:20
and previoulsy i did a for
tab3=[zred d18Ored];
for f=1:0.2:20;
ftab3=tab3*f;
for ti=1:20
t=(1./(4*ftab3*pi))*atan(sum(sin(4*ti*ftab3*pi))/(sum(cos(4*pi*ftab3*ti))));
p(f)=(((sum(sin(2*pi*f*(ti-t)))).^2)/(sum(sin(2*pi*f*(ti-t)).^2)))+((sum(cos(2*pi*f*(ti-t)))).^2)/(sum(cos(2*pi*f*(ti-t).^2)));
end
end
any help would be gratful! thanks

Réponses (1)

Thorsten
Thorsten le 22 Oct 2015
Modifié(e) : Thorsten le 22 Oct 2015
for f=1:0.2:20; and in the loop p(f) = , so you try to eval p(0.2) = ... which is not allowed. f=0.2 is used as a subscript index, but Matlab allows only positive integers as subscripts, like f(1), f(2), and so on.
You can use
flist=1:0.2:20;
for i = 1:numel(flist);
f = flist(i);
% other code
p(i) =
% other code
end

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by