brentaar
Computer
- Nov 30, 2004
- 3
i have a project and every time i run it it gives me this "??? Error: File: C:\MATLAB7\work\square.m Line: 15 Column: 26
Missing variable or function." i have spent many days and i still can't figure it out. there are three parts to the script the main (square.m), the function (fsum), and the given material (pwrspec.m). the problem doesn't make sense, at least to a novice like me. here is the all of the script:
square.m
clf
%trying to find a square wave
time = [0:0.01:10];
T=10;
omega=2*pi*1/T;
fsummation=0
k=1;
gc = ['b','c', 'm', 'k', 'y','g', 'r', 'b'];
for ndx=[1:2:19],
farray(k,
= fsum(time, omega, ndx);
subplot(10,2,ndx)
for m=1:k,
hold on
gc(mod(k,8)+1)
plot(time,farray(m,
’gc')
end
fsummation = fsummation + farray(k,
subplot(10,2,ndx+1)
plot(time, fsummation’r’)
k=k+1;
end
gtext('Archie Brentano SN')
figure
pwrspec(fsummation, 1000,100)
gtext(‘other name’)
fsum.m
function fsum(time, omega, ndx)
%fsummation
fsum = 4/pi*1/ndx * sin(ndx*omega*time)
pwrspec.m
function pwrspec(signal, N, srate)
% pwrspec(signal, N, srate)
% pwrspec computes the power spectrum of a signal and creates a plot
% signal = vector containing signal values
% N = desired length of vector, normally obtained from "length()" function
% srate = sampling rate used to calculate signal, typically twice the value of
% highest frequency
P = fft(signal,N);
n = length(P);
plen = floor(n/2);
power = abs(P(1
len)).^2;
nyquist = 1/2 * srate;
freq = (1
len)/(plen)*nyquist;
stem(freq,power)
title('Power spectrum of signal stream')
xlabel('frequency (Hz)')
ylabel('signal intensity')
grid
Missing variable or function." i have spent many days and i still can't figure it out. there are three parts to the script the main (square.m), the function (fsum), and the given material (pwrspec.m). the problem doesn't make sense, at least to a novice like me. here is the all of the script:
square.m
clf
%trying to find a square wave
time = [0:0.01:10];
T=10;
omega=2*pi*1/T;
fsummation=0
k=1;
gc = ['b','c', 'm', 'k', 'y','g', 'r', 'b'];
for ndx=[1:2:19],
farray(k,
subplot(10,2,ndx)
for m=1:k,
hold on
gc(mod(k,8)+1)
plot(time,farray(m,
end
fsummation = fsummation + farray(k,
subplot(10,2,ndx+1)
plot(time, fsummation’r’)
k=k+1;
end
gtext('Archie Brentano SN')
figure
pwrspec(fsummation, 1000,100)
gtext(‘other name’)
fsum.m
function fsum(time, omega, ndx)
%fsummation
fsum = 4/pi*1/ndx * sin(ndx*omega*time)
pwrspec.m
function pwrspec(signal, N, srate)
% pwrspec(signal, N, srate)
% pwrspec computes the power spectrum of a signal and creates a plot
% signal = vector containing signal values
% N = desired length of vector, normally obtained from "length()" function
% srate = sampling rate used to calculate signal, typically twice the value of
% highest frequency
P = fft(signal,N);
n = length(P);
plen = floor(n/2);
power = abs(P(1
nyquist = 1/2 * srate;
freq = (1
stem(freq,power)
title('Power spectrum of signal stream')
xlabel('frequency (Hz)')
ylabel('signal intensity')
grid