I am getting this error:
1 view (last 30 days)
Show older comments
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 Comment
Star Strider
on 22 Apr 2016
Running only that loop (and creating a ‘t’ vector), I cannot reproduce that error.
Answers (2)
J. Webster
on 22 Apr 2016
I don't get an error, are you sure the code above is what you have in your program?
0 Comments
Image Analyst
on 22 Apr 2016
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.
0 Comments
See Also
Categories
Find more on Logical 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!