Undefined function 'sum' for input arguments of type 'struct' and Error in std.
9 次查看(过去 30 天)
显示 更早的评论
Problem 1:
Undefined function 'sum' for input arguments of type 'struct':
Error in var: xbar = sum(x, dim) ./ n;
Note: I have enter into command window:
1) class(x)and got:
>> class(x)
ans =
struct
2) class(dim)and got:
>> class(dim) Undefined function or variable 'dim'. Why does class(dim) not work? -------------------------------------------------------------------------------------- Problem 2:
Error in std:
y = sqrt(var(varargin{:}));
I do not understand why the error occurs. What would be most likely reasons and how to sort it out? ------------------------------------------------------------------------------------- Many thanks for any help and guidance!
3 个评论
Adam
2017-5-19
doc struct
will tell you about structs, which are just containers for a heap of variables (fields as they are called, for structs). You must know what data you actually want to use though. Clearly you don't want to use the struct in your maths so just access whichever of its fields is the one you want.
采纳的回答
Guillaume
2017-5-19
As you've clearly shown, x is a structure. As the error message also clearly tells you, the sum function is not defined for strutures. Matlab has no idea what the definition of the sum of a structure should be. Neither have we, since it does not make sense generically. What should the sum of
x = struct('ID', {1, 2}, 'name', {'joe', 'jack'})
should be?
With the limited information given, we can't tell you how to solve the issue. Maybe you meant to sum something else, in which case pass the correct variable to sum. Maybe you meant to sum a specific field of the structure(s), in which case you need to explicitly pass these fields to sum. Maybe, you meant to do something else.
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!