thanks buddy u was saying right i modified the code according to u gotcha it is working i hae added zeros in te en becoz i tell u the whole story first i have done max range for the resultant array that would be n i think that u have understand it
ok then i have compar the min value of both indexes of array that is the first element of both array if any array have minmum value greater than the min
than zeros are added at the starting to corresponding array till min
=min(n1orn2) i made case for both so it code can work for any input than i comapre max
with max value of n1 and n2 add zeros at the end of the arrays till max
=max(n1orn2) in this way i made the two arrays of equal dimensions and added thasm code is working i m showing the modified code and its ouput
function [y,n]=sigadd(x1,n1,x2,n2)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
if(n1(1)>n1)
while(n1(1)>n(1))
x1=[zeros(1,1),x1];
n1(1)=n1(1)-1;
end;
end;
if(n2(1)>n(1))
while(n2(1)>n(1))
x2=[zeros(1,1),x2];
n2(1)=n2(1)-1;
end;
end; a=max(n2);
if(max(n2)<max
)
while(a<max
)
x2=[x2,zeros(1,1)];
a=a+1;
end;
end;
b=max(n1);
if(b<max
)
while(b<max
)
x1=[x1,zeros(1,1)];
b=b+1;
end;end;
y=x1+x2;
>> x1=[1 2 3 4 5];
>> n1=-1:3;
>> x2=[1 2 3];
>> n2=0:2;
>> sigaddom(x1,n1,x2,n2)
ans =
1 3 5 7 5
that is the ans it is correct it also works for negative indexing u can check for any input thanks alot for help
Added after 1 minutes:
if u donot understand i will try to demonstrate u more good way