Best practice for saving only one output from a vector-outputting function
이전 댓글 표시
What's the proper way to request only one variable from a vector outputting function, i.e.
[WantThis DontWantThis] = myfun(x, y, ... )
In the past I've just saved the DontWantThis output as a variable called trash and not made reference to it again. This seems rather unprofessional. Is there a cleaner way?
채택된 답변
추가 답변 (1개)
Image Analyst
2013년 4월 14일
You can replace it with a tilde (~)
[WantThis ~] = myfun(x, y, ... )
or just leave it off entirely
WantThis = myfun(x, y, ... )
In the above case, DontWantThis will be thrown away, essentially not returned. I think most people use this latter way, though it can only be used for ignoring return arguments to the right. In other words if you just put one return value:
theOutput = myfun(x, y, ... )
theOutput will be WantThis, not DonotWantThis. Understand?
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!