I am getting this error:

조회 수: 1 (최근 30일)
Ashley Turato
Ashley Turato 2016년 4월 22일
답변: Image Analyst 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