Subtraction of Two sequences

Status
Not open for further replies.

graciousparul

Full Member level 2
Joined
Jan 19, 2008
Messages
128
Helped
6
Reputation
12
Reaction score
0
Trophy points
1,296
Visit site
Activity points
2,053
I have written a code (MATLAB ) to subtract two sequences using functions,The small error is popping up ,please help in debugging the particular error.
function[y1,y2,a,b]= subseq1(n1, x1, n2,x2)
clc;
n=(min(min(n1),min(n2)): max(max(n1),max(n2)));

y1=zeros(1,length)
y2=y1
a=(n>=min(n1))&(n<=max(n1))
b=(n>=min(n2))&(n<=max(n2))
y1(a)=x1
y2(b)=x2
y=y1-y2
subplot(3,1,1)
stem(n1,x1)
title('sequence x1')
xlabel('n1------------' )
ylabel('x1------------ ')
subplot(3,1,2)
stem(n2,x2)
title('sequence x2')
xlabel('n2------------ >')
ylabel('x2------------ >')
subplot(3,1,3)
stem(n,y)
title('subtraction of 2 sequence' )
xlabel('n------------ >')
ylabel('y------------ >')


Error in ==> subseq1 at 6
n=(min(min(n1),min(n2)): max(max(n1),max(n2)));


if i type the following output , we get the same ,
subseq1(-3:3,[3 :2 :15],0 :4,[ 2 :6 )
N= -3 -2 -1 0 1 2 3 4
Y1= 3 5 7 7 8 9 10 -6




Thanks in advance
 

You omitted brackets.
It should be:

n=(min([min(n1),min(n2)]): max([max(n1),max(n2)]));

Regrads

Z
 

n=(min([min(n1),min(n2)]): max([max(n1),max(n2)]))
I have tried ,but when I run ,it still shows the same error
 

Hi,

you have to correct tha call. Te following line:

subseq1(-3:3,[3 :2 :15],0 :4,[ 2 :6 )

is wrong. Try this:

subseq1( [-3:3], [3 :2 :15], [0 :4], [2 :6] )

Regards

Z
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…