Erhy, Your code only works if the input arrays are oriented similiarly (both column or row vectors). For the following input your code would not run:
SumArr = [ 1 2 3 ]; toAdd = [ 7 8 9 10 ]'; SumArr( (length(SumArr)+1) : (length(SumArr)+length(toAdd)) ) = toAdd; !--error 15 Submatrix incorrectly defined. //You could try: function y=add_b2a(a, b) [mx,k]=max(size(a)); if k==1 then y= [a(:); b(:)]; else y= [a(:); b(:)]'; end endfunction // Examples: SumArr = [ 1 2 3 ]; toAdd = [ 7 8 9 10 ]'; add_b2a(SumArr, toAdd) ans = 1. 2. 3. 7. 8. 9. 10. SumArr = [ 1 2 3]'; toAdd = [ 7 8 9 10 ]; add_b2a(SumArr, toAdd) ans = 1. 2. 3. 7. 8. 9. 10. Regards, Rafael -- View this message in context: http://mailinglists.scilab.org/add-number-arrays-efficiently-how-tp4035946p4035976.html Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com. _______________________________________________ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users