Subscript indices must either be real positive integers or logicals.

1. Consider a discrete-time system decribed by the following difference equation:
y[n] = 0.4032x[n] - 0.7039x[n-2] + 0.4032x[n-4] + 0.2876y[n-2] - 0.3121y[n-4]
Implement a Matlab function called dtout.m that computes N output samples (y[0], y[1], ... y[N-1]) given the following:
  • a vector of N+4 input samples (x[-4], x[-3], x[-2], x[-1], x[0], ... x[N-1])
  • a vector of 4 initial conditions for the system (y[-4], y[-3], y[-2], y[-1])
  • the number of output samples N
>> I have this as my fn but getting this error msg"Subscript indices must either be real positive integers or logicals."
function y = dtout(x)
for i = 5:((N-1)+5);
y(i) = 0.4032*x(i) - 0.7039*x(i-2) + 0.4032*x(i-4) + 0.2876*y(i-2) - 0.3121*y(i-4);
end
end

1 Comment

Please, format your code...
function y = dtout(x)
for i = 5:((N-1)+5)
y(i) = 0.4032*x(i) - 0.7039*x(i-2) + 0.4032*x(i-4) + .2876*y(i-2)- 0.3121*y(i-4);
end
end
If you call your function like that, there is no variable N in its workspace, you'll have to pass it as a parameter, or add a line
N = numel(x);

Sign in to comment.

Answers (1)

Run:
dbstop if error
Then run your code by calling the name of the file or function. The debugger will stop on the line throwing the error and you will be able to inspect the variables. You'll likely be trying to index with either a 0 or a decimal.

Categories

Find more on DSP System Toolbox in Help Center and File Exchange

Tags

Asked:

on 5 Feb 2013

Community Treasure Hunt

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

Start Hunting!