Re: [Scilab-users] add number arrays efficiently, how?

2017-03-24 Thread Rafael Guerra
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


Re: [Scilab-users] add number arrays efficiently, how?

2017-03-24 Thread Erhy
PabloF wrote
> May be im missing something, but i think in both cases you need to know
> the arrays in advance, dont you?
> 
> Also, i think  SumArr = [SumArr toAdd] has better performance...
> Perhaps im not understanding the question..

Perhaps merge arrays would be a appropriate subject.

If I code, I'm always uncertain about the orientation of the created array.
My first alternative works in any case.
 



--
View this message in context: 
http://mailinglists.scilab.org/add-number-arrays-efficiently-how-tp4035946p4035974.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


Re: [Scilab-users] add number arrays efficiently, how?

2017-03-23 Thread Samuel Gougeon

Le 23/03/2017 à 00:50, Tim Wescott a écrit :

On Thu, 2017-03-23 at 00:28 +0100, Samuel Gougeon wrote:

Le 22/03/2017 à 23:15, Erhy a écrit :

Hello!
I'm thinking in arrays - and I write

SumArr = [ 1 2 3 ];  toAdd = [ 7 8 9 10 ];
SumArr( (length(SumArr)+1) : (length(SumArr)+length(toAdd)) ) =
toAdd;

How to code it smarter?

SumArr = [SumArr toAdd]


If you know them in advance, yes.


which is the case:


Hello!
I'm thinking in arrays - and I write
SumArr = [ 1 2 3 ];  toAdd = [ 7 8 9 10 ];


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] add number arrays efficiently, how?

2017-03-23 Thread Pablo Fonovich
Hi,
I would have also written

SumArr = [SumArr toAdd]

Why is this answer different to the original?

SumArr( (length(SumArr)+1) : (length(SumArr)+length(toAdd)) ) = toAdd;

May be im missing something, but i think in both cases you need to know the 
arrays in advance, dont you?

Also, i think  SumArr = [SumArr toAdd] has better performance...
Perhaps im not understanding the question..

Obtener Outlook para Android<https://aka.ms/ghei36>



From: users <users-boun...@lists.scilab.org> on behalf of Tim Wescott 
<t...@wescottdesign.com>
Sent: Wednesday, March 22, 2017 8:50:26 PM
To: Users mailing list for Scilab
Subject: Re: [Scilab-users] add number arrays efficiently, how?

On Thu, 2017-03-23 at 00:28 +0100, Samuel Gougeon wrote:
> Le 22/03/2017 à 23:15, Erhy a écrit :
> >
> > Hello!
> > I'm thinking in arrays - and I write
> >
> > SumArr = [ 1 2 3 ];  toAdd = [ 7 8 9 10 ];
> > SumArr( (length(SumArr)+1) : (length(SumArr)+length(toAdd)) ) =
> > toAdd;
> >
> > How to code it smarter?
> SumArr = [SumArr toAdd]
>

If you know them in advance, yes.  My answer was predicated on not
knowing "toAdd" at the same time as the 1x3 SumArr.

> --

Tim Wescott
www.wescottdesign.com<http://www.wescottdesign.com>
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432



___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] add number arrays efficiently, how?

2017-03-22 Thread Tim Wescott
On Thu, 2017-03-23 at 00:28 +0100, Samuel Gougeon wrote:
> Le 22/03/2017 à 23:15, Erhy a écrit :
> > 
> > Hello!
> > I'm thinking in arrays - and I write
> > 
> > SumArr = [ 1 2 3 ];  toAdd = [ 7 8 9 10 ];
> > SumArr( (length(SumArr)+1) : (length(SumArr)+length(toAdd)) ) =
> > toAdd;
> > 
> > How to code it smarter?
> SumArr = [SumArr toAdd]
> 

If you know them in advance, yes.  My answer was predicated on not
knowing "toAdd" at the same time as the 1x3 SumArr.

> -- 

Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432



___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] add number arrays efficiently, how?

2017-03-22 Thread Samuel Gougeon

Le 22/03/2017 à 23:15, Erhy a écrit :

Hello!
I'm thinking in arrays - and I write

SumArr = [ 1 2 3 ];  toAdd = [ 7 8 9 10 ];
SumArr( (length(SumArr)+1) : (length(SumArr)+length(toAdd)) ) = toAdd;

How to code it smarter?


SumArr = [SumArr toAdd]

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] add number arrays efficiently, how?

2017-03-22 Thread Tim Wescott
On Wed, 2017-03-22 at 15:15 -0700, Erhy wrote:
> Hello!
> I'm thinking in arrays - and I write
> 
> SumArr = [ 1 2 3 ];  toAdd = [ 7 8 9 10 ];
> SumArr( (length(SumArr)+1) : (length(SumArr)+length(toAdd)) ) =
> toAdd;
> 
> How to code it smarter?

That's probably the best way to append an array if you can't anticipate
ahead of time how big your ending array will be.  However, each time
you do that Scilab has to allocate space for a bigger array, copy, and
destroy the old copy of the array.

If you DO know how big your ending array will be, then you can speed
things up by creating a zero array of full size, then populating it as
you go.  I.e., in this case you'd create SumArr to be 1x7, then
populate the first three elements, then populate the last four.

-- 

Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432



___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users