Reputation: 1
I'm trying to get the names of inputs and outputs of a function that I've defined while outside the function. In other words, I can't make any change inside the function. I could not find any built-in function that does this. Is there a function that gives details or summary of a function.
For example, myfunc.m
file is like below and I'm calling this function in another script.
function [out1, out2] = myfunc(input1, input2, input3)
operations
end
I need to get the strings 'out1', 'out2', 'input1', 'input2', 'input3'
I'm using Matlab R2018a.
Upvotes: 0
Views: 199
Reputation: 1550
If your allowed to make changes in the myfunc.m
file, I can suggest you try something like:
function [out1, out2] = myfunc(input1, input2, input3)
% 'out1', 'out2', 'input1', 'input2', 'input3'
operations
end
Then in the other script (e.g. test.m):
% stuff...
help myfunc
% things....
It will return
'out1', 'out2', 'input1', 'input2', 'input3'
If your allowed to make changes in the myfunc.m
file, you can also try:
function [out1, out2, string] = myfunc(input1, input2, input3)
operations
string = ["out1", "out2", "input1", "input2", "input3"];
end
And in the script
[~,~,string] = myfunc(1, 1, 1)
It will return:
string =
1×5 string array
"out1" "out2" "input1" "input2" "input3"
EDIT: Since your edits, you are not allowed to intervene in the myfunc.m
file, but you want to read the first line of the function, you can try commands open
or edit
.
In the other script, write open myfunc
or edit myfunc
and it will open the file in a new tab, and you will be able to read it.
Upvotes: 0
Reputation: 1426
You can use inputname for the input, for output there is no straightforward solution but you can try this
Upvotes: 0