필터 지우기
필터 지우기

How to refer to parameter from function in the loop.

조회 수: 2 (최근 30일)
Michael
Michael 2015년 6월 2일
댓글: Michael 2015년 6월 2일
I've got such problem. Whole code is compiling at my teachers computer, whereas on mine it says that: Undefined function or method 'y' for input arguments of type 'double' [Just the part of the code to which it refers]:
for i=round(length(t)/2):length(t)-1
if y(i,1)<-20 && y(i+1,1)>-20
t20=[t20,t(i)];
end
y is used in my func.m file. And now is the question: how to refer to it in my loop? I got no idea why it works there and not on my Matlab.
  댓글 수: 2
Muhammad Usman Saleem
Muhammad Usman Saleem 2015년 6월 2일
After looking on your question i can batter guide you....please share complete question
Muhammad Usman Saleem
Muhammad Usman Saleem 2015년 6월 2일
to me this statement if y(i,1)<-20 && y(i+1,1)>-20 % is used as check means when (i,1)<-20 AND y(i+1,1)>-2 then do with t20???

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

채택된 답변

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh 2015년 6월 2일
편집: Salaheddin Hosseinzadeh 2015년 6월 2일
Dear Michael,
You used y in your myfunc.m function, so it is not recognized in another function if you don't return as an output.
function y = myfunction(a,b,c)
% so this is your y function
% somewhere at the end of your function you have to assign y
% for example
y = a + b;
end
So later in another code, when you're using myfunction you get y back
% this is not myfunction (it's yourFunction) lol
function yourFunction(e,f,g)
% somewhere in this function you're calling myfunction
y = myfunction(a,b,c)
for i=round(length(t)/2):length(t)-1
if y(i,1)<-20 && y(i+1,1)>-20
t20=[t20,t(i)];
end
As I understood this is your problem, if I'm wrong please explain more ;)
  댓글 수: 1
Michael
Michael 2015년 6월 2일
Yep. That's what I needed to have explained. Basics but sometimes (I code once, or twice a semester for projects) I need that guidance.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by