Output matrix for simple function

조회 수: 7 (최근 30일)
Derek . 2014년 4월 14일
댓글: Evangelia Lo . 2021년 11월 12일
I'm brand new to Matlab, and have created a very simple function here to calculate an ion's equilibrium potential:
function y = equipotent(n,X1,X2)
y = (58/n) * log10(X1/X2);
I'd like to do two things: 1) vary X2 for a set of values (1-100) while keeping X1 and n constant. and 2) store all the outputs from the function in a vector for plotting X2 vs y.
Anything helps! Thanks!

답변 (2개)

the cyclist
the cyclist 2014년 4월 14일
If you change your code to
function y = equipotent(n,X1,X2)
y = (58/n) * log10(X1./X2);
then it will give a vector output y for vector input X2, and you should be all set.

Sven 2014년 4월 14일
Hi Derek,
MATLAB has some useful ways to do what you're trying to do. If you use the (.*) operator instead of (*), it will perform a vector multiplication.
Therefore you can adjust your function as follows:
function y = equipotent(n,X1,X2)
y = (58 ./ n) .* log10(X1 ./ X2);
Then you can just run commands:
y = equipotent(4, 3, X2)
Did that help you out?
  댓글 수: 4
Evangelia Lo
Evangelia Lo 2021년 11월 12일
The type of function is

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Electrophysiology에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by