04-20-2010 02:03 PM
Hi, everyone ok? I´m not really....
I´ve got 1D array inputs (x and y) in mathscript, sth like this:
if x>0
w=sqrt(x.^2+y.^2) (the point is for element-wise calculation, i think)
elseif x<0
w=x+999
end
on the front panel i don´t get any numbers... maybe for arrays there is to heed sth. special....(i´ve already changed data type to correct value )
It´s my first time with mathscript.... if anyone also knows some good tutorials i would be grateful...
04-20-2010 02:21 PM
Lecojon,
The "if x>0" will only return a true if ALL elements are greater than 0. Likewise, the elseif x<0 will only return true if ALL elements are less than zero. Chances are that your input array has both positive and negative values. The rest of this assumes that you want your logic to operate element-wise, meaning if the first element of x is positive, then you want the first element of w to be the sqrt of sum of square of first elements in x and y, and if the first element of x is positive, then you just want to add 999 to it. If that's the case, then you need to iterate through your input array before your if logic.
for ii=1:length(x)
if x(ii)>0
w(ii)=sqrt(x(ii)^2+y(ii)^2);
elseif x(ii)<0
w(ii)=x(ii)+999;
end
end
You'll also want to make either your> or < to be inclusive, meaning either (>= coupled with a <) or a (> coupled with a <=) in case one of your values is exactly 0.
With that, I get the following results:
Regards,
04-20-2010 03:20 PM
04-20-2010 04:03 PM
Well, I´ve got more different input-arrays of the same size.
As i see in your example i can take the iteration index "i" for each array, so i don´t have to take f.ex. "j" for array 2 or "k" for array 3...
I´ve got to put a ";" after each calculation of mine....and "%" is for writing comments....
everything right?
In google there is no god tutorial, so i´m working with LV help and by guessing ^^....
04-20-2010 04:16 PM
Sorry, forgot sth.
whats the syntax for two conditions?
if i wanna say: x<0 and y>0 at the same time:
is that
if x<0 and y>0
.
.
.
04-28-2010 10:46 AM
Hello lecojon,
For conjunction of conditions,
if <condition1> & <condition2>
<program>
end
04-28-2010 10:50 AM
04-28-2010 04:01 PM