I am writing a code for DFT and getting this error. 'subscript indices must either be real positive integers or logicals'. My code is as under. Can somebody help me with it? I have used both logical and round commands but still getting the same error
Show older comments
clear all;
clc;
f=60;
Fs=57600;
T=1/Fs;
N=960;
t=0:0.000017:0.02;
m=0;
%x=sin(2*pi*f*t);
y=sqrt(2)*15.66*cos(2*pi*f.*t);
for n=1:960;
x(n)= y(n)
real(n)=cos(2*pi*(1/960)*(n-1));
imag(n)=sin(2*pi*(1/960)*(n-1));
m=m+1
end
for n=1:960;
F(n)=y(n)*(real(n)+imag(n))
end
plot(t,F(n))
1 Comment
Walter Roberson
on 24 May 2015
You never use t in your computation, but you try to plot against t.
After the "for" loop just before your plot(), n will end up with the value 960. When you try to plot(t,F(n)) you are telling it to plot(t,F(960)) where F(960) is a single value. That will produce a plot, but it will not be a useful plot.
Please note that when you assign to F(n) you are not creating a formula, you are assigning a definite numeric value.
Accepted Answer
More Answers (0)
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!