Passing Python function input arguments from Matlab
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Chandra Sekhar Kommineni
le 21 Sep 2022
Réponse apportée : Al Danial
le 4 Oct 2022
Hello all,
I'm trying to use external python libraries in side matlab, but I'm facing some problems in passing array of size 100k. Python is not accepting ndarray. I'm not sure, how to pass the input arguments, can someone explain what I'm doing wrong. Thank you, Here is my matlab code,mat file and python code attached.
clear all;
arrival_time = fileparts(which('arrivaquant.py'));
if count(py.sys.path,arrival_time) == 0
insert(py.sys.path,int32(0),arrival_time);
end
%%
AT1_ms=data2(:,2);
TT1_us=data2(:,3);
LDV1_mps=-data2(:,4);
%%
%acfspc(t,u,w,dt,K2,meanrem=True,atw=False,locnor=False,selfproducts=False):
% t: array of real values, random arrival times (single block
% # or whole LDV data set)
% # u: array of real or complex values, velocities (single block
% # or whole LDV data set)
% # w: array of real values, individual weights (single block
% # or whole LDV data set), e.g. transit times, not used if
% # atw==True)
% # dt: real value, fundamental time step, e.g. temporal resolution
% # of the correlation function
% # K2: positive integer, maximum lag time in the estimated correlation
% # function in units of dt, yields a correlation function estimated
% # for lag times from -K2*dt to K2*dt (
%pyOut = py.arrivaltime_quantization.acfspc(t,u,w,dt,K2,meanrem=True,atw=False,locnor=False,selfproducts=False);
fs= 1e3/mean(diff(AT1_ms));
dt1_ms= 1/fs; %fs=mean data rate
%clear classes
mod=py.importlib.import_module('arrivaquant');
py.importlib.reload(mod);
%% %pyOut = py.arrivaltime_quantization.acfspc(t,u,w,dt,K2,meanrem=True,atw=False,locnor=False,selfproducts=False);
[test,t,x,c] = py.arrivaquant.acfspc(py.numpy.ndarray(AT1_ms),py.numpy.ndarray(LDV1_mps),py.numpy.ndarray(TT1_us),dt1_ms,6000,meanrem=py.bool('True'),atw=py.bool('True'),locnor=py.bool('True'),selfproducts=py.bool('True'));
I'm getting following error, Python Error: ValueError: maximum supported dimension for an ndarray is 32, found 109156
Please let me know what i'm doing wrong here. Thank you so much in advance,
0 commentaires
Réponse acceptée
Al Danial
le 4 Oct 2022
Wrap your MATLAB matrices with py.numpy.array() instead of py.numpy.ndarray() in your call.
Plus de réponses (1)
Al Danial
le 4 Oct 2022
Integers are tricky because what looks like an integer in MATLAB is actually a double unless you explicitly cast it, for example with int64(). As you noted, this causes problems for Python which will reject a double in many cases. I talk about this exact case in my presentation at the 2022 MATLAB Expo.
0 commentaires
Voir également
Catégories
En savoir plus sur Call Python from MATLAB 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!