Hello fugimoto2005,
You may use find():
b = x
k = find(x>1)
b(k) = x(k)+1
Just do the same to process the second case.
Regards
samuelgougeon2015
Le 19/04/2015 17:57, fujimoto2005 a écrit :
I define a function with a scalar argument and use it with a matrix argument.
I want to get the matrix whose entry is the functional value for each entry
of a matrix argument.
When the function contains no "if then" close, I get the desired result as
the following function "f".
However when the function contains "if then "close, the function returns the
inverse matrix as the following function "g".
It is because "x>1" is false as a matrix and “else part” is executed as
inverse matrix calculation.
I want to get the code that "if then" is applied for each entry of matrix.
Please teach how to get such a code.
**code****
function a=f(x)
a=x+1
endfunction
X=[1,2;3,4]
f(X)
function b=g(x) if x>1 then
b=x+1
else
b=1/x
end
endfunction
X=[1,2;0.1,-0.1]
g(X)//returns inverse(X)
--
View this message in context:
http://mailinglists.scilab.org/qustion-on-functional-argument-tp4032100.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at
Nabble.com.
_______________________________________________
users mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[email protected]
http://lists.scilab.org/mailman/listinfo/users