Create unknown amount of vectors automatically (no cell-arrays allowed due to compatibility issues with Python)

1 回表示 (過去 30 日間)
Hello,
I am looking to pass numeric data from Matlab to Python. As far as I'm concerned, the API does not support any kind of container, so no cells or structs are allowed. The idea is to have a function passing multiple vectors with each vector having info on one object (a car). The number of cars, i.e. the number of vectors to be created, is not known before runtime.
varargout creates a cell-array and is therefore unsuitable;
In Python, I can declare
*argument
and will get any number of arguments I create during runtime. Is there something similar in Matlab or is there any other trick?
I have considered combining all data into one vector and un-combining it once it has reached Python, this is not beautiful though.
(Better yet: Does someone know a container-type format which passes through R2018b-Python-API.)
Thank you in advance
Unsupported MATLAB Types for 2018 Python API
  • Multidimensional char or cell arrays
  • Structure arrays
  • Sparse arrays
  • categorical,table,containers.Map,datetime types
  • MATLAB objects
  • meta.class (py.class)
  3 件のコメント
Lukas Köhler
Lukas Köhler 2021 年 10 月 21 日
Thank you for your answer! Your presumption is correct. Unfortunately, the 2018 Python API does not even allow for arrays to be passed; I shall clarify this in the question. Hence I'm looking for this illegal-seeming multiple-vector solution.
dpb
dpb 2021 年 10 月 21 日
Then it would seem you're forced to use a looping construct with 1D arrays or the one vector approach.
I don't see the latter as being that big a deal, surely Python has the facility to reshape a vector, doesn't it? If you either prepend the size info to the data or pass it separately, it wouldn't seem difficult (conceptually, anywhooo...)

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

回答 (1 件)

Pranjal Kaura
Pranjal Kaura 2021 年 10 月 27 日
Hey,
You could go through the link 'Pass Data to Python', particularly the 'Passing Matrices and Multidimensional Arrays' subsection to know more about passing multidimensional arrays from MATLAB to python.
Hope this helps!

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by