Hi, I have been trying to run a script and got the error: Undefined operator '+' for input arguments of type 'struct'. Error in coarsegrain (line 41) sum = sum + y(scale*i + j); Error in mse (line 35) scaled = coarsegrain(method,y,scale);.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Massilon Toniolo da Silva
am 20 Mai 2017
Beantwortet: Walter Roberson
am 20 Mai 2017
Hi,
I have been trying to run a script and got the error: Undefined operator '+' for input arguments of type 'struct'.
Error in coarsegrain (line 41) sum = sum + y(scale*i + j); Error in mse (line 35) scaled = coarsegrain(method,y,scale);
Displayed in the work space: maxScale=3,
val 3x1280 double,
x 1x1 struct. Could someone give me some guidance how to solve the problem?
Many thanks!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 20 Mai 2017
The reason was already explained to you in https://www.mathworks.com/matlabcentral/answers/340974-undefined-function-sum-for-input-arguments-of-type-struct-and-error-in-std#comment_455195
"If 01911m is a MAT-file, the syntax you've used for load will make x into a struct array with one field per variable in the MAT-file. You probably don't want to take the std of the struct but you want to operate on one of the fields of the struct instead"
You should look more closely at the documentation for load(): https://www.mathworks.com/help/matlab/ref/load.html#outputarg_S . When you assign the output of load() to a variable then the output is:
"Loaded variables, returned as a structure array, if filename is a MAT-File.
Loaded data, returned as an m-by-n array of type double, if filename is an ASCII file. m is equal to the number of lines in the file, and n is equal to the number of values on a line."
You are encountering the MAT version, so the output of load() is a structure array.
0 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!