How do I recall a MATLAB function that has already been saved on my computer?

조회 수: 5 (최근 30일)
Robert  Flores
Robert Flores 2017년 10월 15일
댓글: Image Analyst 2017년 10월 15일
Below are my two scripts of code, one is a function called keplersolve and the other is a script called Test1. When I am trying to run Test1 it won't recall my function keplersolve, I have already ran keplersolve before running Test1, so MATLAB has it in its workspace. If anyone can help me, it'll be much appriciated.
%keplersolve clc clear close all
% E = keplersolve(M,e) function E = keplersolve(M,e) MAXITER = 100; % in case the loop does not converge TOL = 1e-11; % tolerance for convergence En = M; % first guess fn = En - e*sin(En) - M; % f(E) that we want to be zero iter = 1; % count the iterations while ( abs(fn) > TOL ) En = En - fn/(1-e*cos(En)); fn = En - e*sin(En) - M; iter = iter+1; if (iter>=MAXITER) error('Did not converge'); exit end end E = En end
%Test1 clc clear close all
t_T = input('time since periapsis: ') a = input('semi-major axis: ') e = input('orbits eccentricity: ')
T_T = (t_T)*60; % This is a conversion to minutes into seconds
mu = 3.986*10^5;
n = sqrt(mu/(a^3)); % Mean anamoly M = n*(T_T); % Mean motion
keplersolve_(M,e)
  댓글 수: 3
Robert  Flores
Robert Flores 2017년 10월 15일
Thank you so much, what you told me to do cleared it up.
-Robert Flores
Image Analyst
Image Analyst 2017년 10월 15일
No it didn't - your code formatting is still messed up. Maybe you were talking about my answer below though.

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

답변 (1개)

Image Analyst
Image Analyst 2017년 10월 15일
Remove these lines from the beginning of keplersolve:
clc
clear
close all
It should start with the "function" line. Otherwise that function is privately nested in a script and won't be able to be seen from a separate m-file.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by