How can I have multiple outputs for a function evaluating various elements?

1 view (last 30 days)
Hi! I'm new into this. I'm writing a function file and I want to be able to input a vector, evaluate each element with the same function and obtain an output that has each element's result. Here is what I'm writing:
function IF=myfunction(P,T)
display (IF)
My inputs are P=[10 20] and T=[30 40] and it has an error saying "error using mrdivide; matrix dimensions must agree".

Accepted Answer

madhan ravi
madhan ravi on 31 Aug 2018
Edited: madhan ravi on 31 Aug 2018
function IF=myfunction(P,T)
a=1.28+15.*(1./P+0.05)+exp(100./T); %USE ELEMENT-WISE OPERATIONS
disp(IF) %not Display it’s disp
madhan ravi
madhan ravi on 1 Sep 2018
Edited: madhan ravi on 1 Sep 2018
@Eduardo Chacin like also sir Image Analyst said in addition read the link below for better understanding element wise operations:

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 31 Aug 2018
Use dot slash like this:
function IF = myfunction(P, T)
IF = 501.28 + 15 * (1 ./ P + 0.05) + exp(100 ./ T)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by