Error in function ?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
when I run it I got the following error
Undefined function or variable 'TBack'.
Error in interp (line 18)
TBack;
Error in physio (line 10)
v=interp(t);
Error in testingfile (line 47)
p1=physio(t(i)+alfa);
채택된 답변
0 개 추천
I think that the statement
TBack;
at the end of the interp function does not belong. Just delete it.
Here is another issue:
In your interp function, you cannot execute the loop for k=1 to length (t_test) because you are referencing element (k+1) this will cause you to have an "out of bounds" subscript error when k=length(t_test).
The loop should run for k=1 to length(t_test)-1
댓글 수: 7
Willim
2019년 2월 10일
Output argument "TBack" (and maybe others) not assigned
during call to "interp".
Error in physio (line 10)
v=interp(t);
Error in testingfile (line 47)
p1=physio(t(i)+alfa);
After changing them I still have the error
I think that the error with "TBack" is that the function output needs to be defined for all logic paths in the code.
You have one logic path (the first "if" condition) where this variable will not be assigned. You have two choices to fix this:
1) Add a definition for TBack in your first "if" statement, e.g.
if t1 <=0 || t1 >9
TBack = -99;
...
end
elsif
...
This represents a "nonsense" condition where the function is undefined.
2) Or you can assign a default value for TBack before the if statement.
This way, TBack will always have a value assigned.
function [TBack]=interp(t1);
t_test=[0 1 2 4 5 7 8 9];
T = [0 5 8 -6 -6 6 3 -4];
% find the t loction
for k=1:length(t_test)-1
if t1 <= 0 || t1 > 9
fprintf('Undefined \n')
TBack=-1;
% elseif t1 == 9
% TBack= -4;
break
elseif t_test(k) <= t1 && t_test(k+1)> t1
TBack=(((T(k+1)-T(k))/(t_test(k+1)-t_test(k)))*(t1-t_test(k)))+T(k);
end
end
%TBack;
end
it still has the error
Willim
2019년 2월 10일
I think it's going well when I change the for loop to 7 , but the result is completely wrong
%% The main
t=[1e-23 1 2 4 5 7 8 9];
x=1;
alfa=0.1;
h=0;
for i=1:1:7
p1=physio(t(i)+alfa);
p2 = physio(t(i));
h(i)=alfa*(p1- p2)
x(i+1)=x(i)*(1+0.8*h(i)*(1-(x(i)/25)))
end
plot(t,x)
hold on
title('The Locistic Model of a Population System Driven by physiological time')
xlabel('Time ,t')
ylabel('Population Size')
%% ode 45
tspan = [0 9];
x0 = 1;
[t,y] = ode45(@(t,x) 0.8*x*(1-(1/25)*x), tspan, x0);
plot(t,y)
grid on
title('The Locistic Model of a Population System Driven by Chronological time')
xlabel('Time ,t')
ylabel('Population Size')
If you are intending to interpolate T using t_test , then the correct formula is:
TBack = (t1-t_test(k))/(t_test(k+1)-t_test(k)) * (T(k+1)-T(k)) + T(k);

I just noticed that you commented out the condition
elseif t1 == 9
If you do this, then you should change the conditional on the next statement from
elseif t_test(k) <= t1 && t_test(k+1) > t1
to
elseif t_test(k) <= t1 && t_test(k+1) >= t1
otherwise, there is no defined action for t1 = 9.
I'm afraid that I cannot help you if you do not like the results, since I do not understand the problem you are working.
But if I have been helpful, please accept my answer.
Perhaps you should clean up your code, and then post a new question showing the code and the results you are getting, and why you think it is not right (i.e. what is the expected result?). Maybe someone else knows about this particular type of problem.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
