Undefined function 'sum' for input arguments of type 'struct' and Error in std.
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Massilon Toniolo da Silva
am 19 Mai 2017
Kommentiert: Walter Roberson
am 20 Mai 2017
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 Kommentare
Adam
am 19 Mai 2017
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.
Akzeptierte Antwort
Guillaume
am 19 Mai 2017
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!