0
votes

I am having some problems defining a simple function in Matlab, the error says: not enough input arguments! but the function only needs one argument. The input is A, a matrix (100 rows, 4 columns) and what I expect is another matrix.

I save MyFun.m as a file in order to call it later with @MyFun.

function [y]= MyFun(A)

a=[nanmean(A(:,3)),nanmean(A(:,4))];

b=sqrt(a(:,1).^2+a(:,2).^2);

c=((atan2d(a(:,2),a(:,1)))./2)+90;

if c<=90

    c=c+90;  

else

    c=c-90;
end

d=[nanstd(A(:,3)),nanstd(A(:,4))];

y=[a,b,c,d]

clear a b c d
end
1
I suspect that you have a variable or function also called "MyFun" in your workspace , I suggest you clear your workspace and try again. - Y. Chang
Are you passing an argument to your function? Something like A = rand(100,4); y = MyFun(A) That works well for me. Your code runs just fine. - Thales
Call your function using parentheses: MyFun(input), by adding an @ you are creating a function handle instead of executing the function. But without more info on how you call the function, we cannot answer your question. - rinkert
Also note that Myfun and MyFun are not the same. The file name is the name of the function you call. - Cris Luengo

1 Answers

0
votes

I don't see any issue with what you have. I 2nd what Y.Chang said about making sure you don't have another variable or function called MyFun.

The other issues might be:

  1. You clear your variables at the end. Having the clear and end on the same line might do something wonky. I would just remove that since those variables will be cleared automatically when the function exits.

  2. It depends on how you call it when you use the @ notation. You need to be sure the input parameter is being passed in correctly there.