How can I call one of the outputs of a function in another script and plot it?

1 回表示 (過去 30 日間)
Sina
Sina 2013 年 10 月 29 日
コメント済み: dpb 2013 年 10 月 29 日
Hi.
I have a function:
----------------------------
function F = tethsolve3(p,H,L);
x0=[2;2];
g=9.82;
mu=0.0141*g;
% [x,fval]=fsolve(@Teth3,x0);
[x,fval] = fsolve(@(x) Teth3(x, p, H, L), x0);
Th2Radian=atan(sinh((x(1)+p)*mu/x(2)));
T2=x(2)/cos(Th2Radian)
end
-------------------------------
I need to plot one of the outputs of the function in another script for different inputs, as follows:
------------------- L=108;
H=100;
g=9.82;
mu=0.0141*g;
for p=0.01:1:10;);
tethsolve3(p,H,L);
T2=T2
p=p
plot(p,T2)
hold on
grid on
end -------------------------------
But there is an error. I guess it's because T2 is not really an output. Do I need to use a function handle???!
Please advise.
Thanks a lot.
  1 件のコメント
dpb
dpb 2013 年 10 月 29 日
No, you need to return back to the caller any outputs from your function(s) that you need to have for further use--functions, otherwise, are pretty much useless for computations.
You wrote
function F = tethsolve3(p,H,L);
but F isn't ever defined so the end result of calling tethsolve3 is--well, nothing.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by