How do I link my key.m nargin function (with switch statements) in my main.m script?

11 views (last 30 days)
Hi guys, so I'm using MATLAB R2017b and I tried to link my function called key.m and used nargin to switch between the arguments. I want to link this in my main.m file, so that I can run it. The function with nargin looks like this,
function [cm, percentage]= key(T1,T2,T3)
if nargin==2
switch T1
case ....
case ....
end
switch T2
case ....
case ....
end
[cm, percentage] = key(T1,T2)
elseif nargin==3
switch T1
case ....
case ....
end
switch T2
case ....
case ....
end
switch T3
case ....
case ....
end
[cm, percentage] = key(T1,T2,T3)
I want to link this in my main.m script and run it. Any ideas will be really helpful and highly appreciated. Thank you <3 :)

Answers (1)

Rik
Rik on 28 Apr 2018
Just put the following line in your main.m file
[cm, percentage] = key(T1,T2,T3);
As long as key.m is on your Matlab path (so either in your current folder, or in one of the folders that you told Matlab to look for function), you can just use key as you would with any other function.
Just to clarify, you are aware that putting [cm, percentage] = key(T1,T2,T3) in your key.m file will cause a loop?

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!