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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Solver 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