ValueError: only a scalar struct can be returned from MATLAB

24 次查看(过去 30 天)
I tried to use matlab.engine in python to import a struct from Matlab. my operation system is macOS Sierra, and the error message is :
File "/lib/python2.7/site-packages/matlab/engine/fevalfuture.py", line 82, in result
self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
ValueError: only a scalar struct can be returned from MATLAB
The values in the fields of the struct are cell, logical, single, unit8, and unit16. I am not sure what scalar struct refers to. Has anyone met the same problem before ?
Thanks!
  1 个评论
Walter Roberson
Walter Roberson 2017-9-30
A scalar struct is one for which size() of the struct itself says [1 1]. It does not matter what size the fields contained in the struct are, just the size of the struct itself. For example,
test1.this = 1:20;
test1.that = 'hello';
test2(1).this = 1;
test2(1).that = char('what','is','the','result','here?');
test3(1).this = 1:20;
test3(1).that = 'hello';
test3(2).this = 1;
test3(2).that = char('what','is','the','result','here?');
With these lines, size(test1) and size(test2) will both be [1 1] -- they are scalar structures, no matter how big the fields they hold are. Referring to test1.that would give you the single result 'hello' .
However, size(test3) will be [1 2]: it is not a scalar structure, it is a structure array. Referring to test3.that would give you a comma-separated list of two results, the first of which was 'hello' and the second of which was the char array, because of "structure expansion".

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by