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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by