I am getting this error:

1 次查看(过去 30 天)
Ashley Turato
Ashley Turato 2016-4-22
I am trying to use the following Matlab function:
function [ N,n ] = rn( t )
N=size(t,2); rand('seed',0);
n(1)=rand-0.5; for i=2:N;
n(i)=0.3*n(i-1)+1.5*(rand-0.5);
end
with this script:
clear all
clc
t=0:0.02:10;
x=0.5.*(ur(t-2)-2*ur(t-4)+ur(t-6));
[A,B]=rn(t);
y=B+x; %adding the noise to the triangular pulse signal
plot(t,y);
however, I am getting the following error:
Subscript indices must either be real positive integers or logicals.
Error in rn (line 7)
n(i) = 0.3*n(i-1)+1.5*(rand()-0.5);
Error in engg177parte (line 5)
[A,B]=rn(t);
Why is this error occuring?
  1 个评论
Star Strider
Star Strider 2016-4-22
Running only that loop (and creating a ‘t’ vector), I cannot reproduce that error.

请先登录,再进行评论。

回答(2 个)

J. Webster
J. Webster 2016-4-22
I don't get an error, are you sure the code above is what you have in your program?

Image Analyst
Image Analyst 2016-4-22
In my file, test3.m I put this:
function test3
% clear all
clc
t=0:0.02:10;
x=0.5.*(ur(t-2)-2*ur(t-4)+ur(t-6));
[A,B]=rn(t);
y=B+x; %adding the noise to the triangular pulse signal
plot(t,y);
function [N, n] = rn(t)
N=size(t,2);
rand('seed',0);
n(1)=rand-0.5;
for i=2:N
n(i)=0.3*n(i-1)+1.5*(rand-0.5);
end
and I get this:
Undefined function or variable 'ur'.
Error in test3 (line 5)
x=0.5.*(ur(t-2)-2*ur(t-4)+ur(t-6));
as you can see, you forgot to tell us what you're using for ur. I'll check back and try again later once you tell me what ur is.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by