Function ontput missed or not assigned

조회 수: 1 (최근 30일)
Tonghui Zhang
Tonghui Zhang 2019년 6월 10일
댓글: Walter Roberson 2019년 6월 10일
Dear all,
I am confronted with a problem now. What I want to do is to formulate a function like
[y1,y2,y3]=f[x1,x2]
Note that the output and input dimensions are constant. Not all outputs will be assigned a value so in Matlab it will report an error. My question is that is there any method that I can assign values to the missed outputs outside when I call the function?
Thanks a lot
  댓글 수: 3
per isakson
per isakson 2019년 6월 10일
편집: per isakson 2019년 6월 10일
"is there any method that I can assign values to the missed outputs outside [the function, f ]"
The simple answer is no - afaik.
Tonghui Zhang
Tonghui Zhang 2019년 6월 10일
편집: per isakson 2019년 6월 10일
Hi,
The function code is as followed
function [y1 y2]=xxx(u)
if u<10
y1=1
else
y2=1
end
end
The error is 'when you are calling function xxx, no value is assigned to y2'

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

답변 (1개)

KSSV
KSSV 2019년 6월 10일
function [y1 y2]=xxx(u)
if u<10
y1=1 ;
y2= [] ;
else
y1 = [] ;
y2=1 ;
end
end
  댓글 수: 2
Tonghui Zhang
Tonghui Zhang 2019년 6월 10일
Thank you for your answer, I know this can solve the problem. My problem is that I don't want to update y2 in this case so, is there any method that I can update the missed output outside the function?
Walter Roberson
Walter Roberson 2019년 6월 10일
No, there is no method to do that. You can use try/catch to handle the error more smoothly, but the error handling will be invoked before the outputs that are present are assigned.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by