Effacer les filtres
Effacer les filtres

ValueError: only a scalar struct can be returned from MATLAB

34 vues (au cours des 30 derniers jours)
Po-Hsuan Huang
Po-Hsuan Huang le 30 Sep 2017
Commenté : Walter Roberson le 30 Sep 2017
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 commentaire
Walter Roberson
Walter Roberson le 30 Sep 2017
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".

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by