[Scilab-users] add number arrays efficiently, how?
Rafael Guerra
jrafaelbguerra at hotmail.com
Fri Mar 24 13:16:28 CET 2017
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.
More information about the users
mailing list