How to allow same function name to be used various ways?

I understand how to achieve this interms of the outputs and code exercuted but how do you allow the pop out box display all different possible inputs such as the plot example I've attached

답변 (3개)

Ameer Hamza
Ameer Hamza 2020년 4월 13일

1 개 추천

In mac, the suggestion lists pop up by simultaneously pressing Control and 1. I guess the same will work on windows.

댓글 수: 3

Sorry I don't think I was clear. I meant when I make my own function I can only get one line to come up eg:
Ok. I get it now. If you want such suggestion pop up for your own function, then you need to create the JSON file as described here: https://www.mathworks.com/help/matlab/matlab_prog/customize-code-suggestions-and-completions.html
I have got this working with a live script. Is it possible to get it working with a command line based .m file ?

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

Image Analyst
Image Analyst 2020년 4월 13일
You can use varargin and then check the inputs
function output = MyFunction(varargin)
if nargin == 1
value1 = vargin{1}
value2 = 20; % Some default
else if nargin == 2
value1 = vargin{1}
value2 = vargin{2}
end
I think that's the easiest, and what I do. But the official way is to use the inputparser: https://www.mathworks.com/help/matlab/input-and-output-arguments.html?s_tid=CRUX_lftnav
Steven Lord
Steven Lord 2020년 4월 13일

0 개 추천

You can customize completions for the functions you've written if you're using release R2018a or later.

댓글 수: 1

I have got this working with a live script. Is it possible to get it working with a command line based .m file ?

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

카테고리

도움말 센터File Exchange에서 Create Custom UI Components에 대해 자세히 알아보기

질문:

2020년 4월 13일

댓글:

2020년 4월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by