Output matrix for simple function
2 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
回答 (2 件)
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.
0 件のコメント
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)
figure
plot(X2,y)
Did that help you out?
4 件のコメント
Evangelia Lo
2021 年 11 月 12 日
I have one similar question ... I want ti make a function which will take p, v, d and D as input, and will calculate the pressure drop register (Dp), for d / D from 1 to d / D (derived from the input data), and in steps of (1/100 ) * (d / D)... How can i do it ?
参考
カテゴリ
Help Center および File Exchange で Behavior and Psychophysics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!