Azzera filtri
Azzera filtri

ValueError: only a scalar struct can be returned from MATLAB

34 visualizzazioni (ultimi 30 giorni)
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 Commento
Walter Roberson
Walter Roberson il 30 Set 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".

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by