フィルターのクリア

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 件のコメント
Massilon Toniolo da Silva
Massilon Toniolo da Silva 2017 年 5 月 19 日
Dear Stephen, I thank you very much for this valuable information! My Matlab skills are quite limited and I often miss the point. Still, I am getting an error because my input signal x is of the class structure. What should I do to get my script working. I do not understand struct properly. Thanks very much!
Adam
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
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 件のコメント
Massilon Toniolo da Silva
Massilon Toniolo da Silva 2017 年 5 月 20 日
Hi Steven, thank you for your answer. I have used y = x.data; and did not work. What should data stand for? Could you perhaps clarify on that? For instance, with an example? Many thanks Massilon
Walter Roberson
Walter Roberson 2017 年 5 月 20 日
Show us the output of
whos -file 01911m.mat

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by