필터 지우기
필터 지우기

How to add the variables in a function to your workspace?

조회 수: 3 (최근 30일)
azarang asadi
azarang asadi 2020년 3월 18일
댓글: Adam Danz 2020년 3월 19일
So I have a function let's say like this y = fun(x) and to get the y from x, I am defining some other variables let's say like c, that I need to first compute and put it in another formula to compute y. ( F= ma , and my y here is F and my c here is a) .So my question is that how I can see what the values of c are and add it as a variable in the workspace?

답변 (1개)

Adam Danz
Adam Danz 2020년 3월 19일
편집: Adam Danz 2020년 3월 19일
Add the variable as an output.
function [y, c] = fun(x)
c = . . .
y = . . .
end
If you only want one of the outputs when calling the function,
y = fun(x);
[~, c] = fun(x);
  댓글 수: 2
John D'Errico
John D'Errico 2020년 3월 19일
편집: John D'Errico 2020년 3월 19일
While I know that Adam knows this, to be clear for the reader..._
Remember that you also need to declare them in the function header as those variables to be returned. So your function header would look like this:
function [y,c] = fun(x)
Adam Danz
Adam Danz 2020년 3월 19일
Thanks John, I improved the answer based on your comment.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by