Undefined function 'sum' for input arguments of type 'struct'.
Show older comments
When I want to find a mean of a matrix A of size 1 by 18, the MATLAB give an error:
Undefined function 'sum' for input arguments of type 'struct'. Error in mean (line 30) y = sum(x,dim)/size(x,dim);
How can I solve this problem? Thanks.
Answers (1)
Geoff Hayes
on 6 Sep 2014
Edited: Geoff Hayes
on 6 Sep 2014
omid - the error message is telling you that the input to your sum function is a struct. Either one (or both) of x or dim is a struct. In the Command Window, type
class(x)
followed by
class(dim)
What is the result from each statement? Depending upon which one is the struct, you will have to modify the inputs accordingly.
2 Comments
Massilon Toniolo da Silva
on 19 May 2017
Hi Geoff,
I have the same error and entered class(x) which resulted in x being the struct. Afterwards, I entered class(dim) and got undefined function or variable 'dim'. More precisely, which input should I modify and how should it be modified? Why the command class(dim) did not work? Could you please help me in matter? My Matlab skills are, unfortunately, very limited. Could you, therefore, explain a simple matter what went wrong? I would be very thankful for any help and guidance. Kind regards, Massilon
Geoff Hayes
on 19 May 2017
Massilon - in the code provided by omid (see question), there was a variable called dim. If you have not defined this variable then you will get the error that you are observing.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!