Re: [Scilab-users] add value to each element of an array, also to an empty one

2017-03-24 Thread Rafael Guerra
An ugly alternative without find and without the if as requested:

A =  [ -1 2 7 ];

I = (A>10).*(cumsum(ones(A))+1);
I(I==0) = []
I  =
 []

I = (A>0).*(cumsum(ones(A))+1);
I(I==0) = []
I  =
3.4. 

Rgds,
Rafael



--
View this message in context: 
http://mailinglists.scilab.org/add-value-to-each-element-of-an-array-also-to-an-empty-one-tp4035989p4035996.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 value to each element of an array, also to an empty one

2017-03-24 Thread Erhy
Samuel GOUGEON wrote
> Not in Scilab 6, for the time being. I assumed that you were using Scilab
> 6.

so I will jump to version 6
Thank you!




--
View this message in context: 
http://mailinglists.scilab.org/add-value-to-each-element-of-an-array-also-to-an-empty-one-tp4035989p4035993.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 value to each element of an array, also to an empty one

2017-03-24 Thread Samuel Gougeon

Le 24/03/2017 à 21:08, Erhy a écrit :

Samuel GOUGEON wrote

  1. length(I)==0 means I==[] and then I+1 == []+1 ==[]  as if nothing

But in my examples
I = [];
Iplus = I + 1;
then Iplus is 1

Not in Scilab 6, for the time being. I assumed that you were using Scilab 6.
In Scilab 5: i know nothing simpler than testing if I~=[]


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


Re: [Scilab-users] add value to each element of an array, also to an empty one

2017-03-24 Thread Erhy
Samuel GOUGEON wrote
>  1. length(I)==0 means I==[] and then I+1 == []+1 ==[]  as if nothing

But in my examples
I = [];
Iplus = I + 1;
then Iplus is 1




--
View this message in context: 
http://mailinglists.scilab.org/add-value-to-each-element-of-an-array-also-to-an-empty-one-tp4035989p4035991.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 value to each element of an array, also to an empty one

2017-03-24 Thread Samuel Gougeon

Hello Erhy,

Le 24/03/2017 à 20:36, Erhy a écrit :

Hello!
Again a basic question.
e.g.
A =  [ 1 2 3 ];
I = find( A > 10);
if length(I) > 0 then
I = I + 1;
end

Is there a alternative
*without the if ?*


Yes, just:
I = I + 1
The if is useless:

1. length(I)==0 means I==[] and then I+1 == []+1 ==[]  as if nothing
   was done
2. otherwise, just add 1


I miss the .+ operator.


So do i, sometimes.

Samuel

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


[Scilab-users] add value to each element of an array, also to an empty one

2017-03-24 Thread Erhy
Hello!
Again a basic question.
e.g.
A =  [ 1 2 3 ];
I = find( A > 10);
if length(I) > 0 then
I = I + 1;
end

Is there a alternative
*without the if ?*

I miss the .+ operator.

Thank you  



--
View this message in context: 
http://mailinglists.scilab.org/add-value-to-each-element-of-an-array-also-to-an-empty-one-tp4035989.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