Not Enough Input Arguments

2 visualizzazioni (ultimi 30 giorni)
아영 박
아영 박 il 4 Set 2024
Risposto: Kanishk il 5 Set 2024
I have imported a MATLAB code into a Python project in Visual Studio, using the MATLAB engine for Python. The MATLAB code generates a roughness profile for a surface and exports the information into an input file. The variables required for this process are Lx, Ly, Lz, N, sn_x, sn_y, WB_a, and WB_b. These variables control the size and roughness of the surface.
In MATLAB, these variables were entered in the command window, but in Visual Studio, I couldn’t find a similar command window, so I entered the variables as shown in the attached code. However, when I try to run the code, I keep getting a MatlabExecutionError related to missing input arguments on line 24 of the MATLAB file. Line 24 contains the following code: R_sample = -WB_a * gamma(1 + 1/WB_b) + WB_a * (-log(1-rand(sn_y, sn_x))).^(1/WB_b);.
I'm wondering if the way I'm entering the variables is incorrect, or how I can resolve this error. Any suggestions are appreciated.
import matlab.engine
eng = matlab.engine.start_matlab()
Lx = 1
Ly = 1
Lz = 0.2
N = 5
sn_x = 30
sn_y = 30
WB_a = 0.05
WB_b = 2
eng.workspace['Lx'] = Lx
eng.workspace['Ly'] = Ly
eng.workspace['Lz'] = Lz
eng.workspace['N'] = N
eng.workspace['sn_x'] = int(sn_x)
eng.workspace['sn_y'] = int(sn_y)
eng.workspace['WB_a'] = WB_a
eng.workspace['WB_b'] = WB_b
eng.Rand_surf(narfout=0)
eng.quit()
  2 Commenti
Steven Lord
Steven Lord il 4 Set 2024
This line looks like a probably typo. Are you sure it wasn't supposed to be nargout instead of narfout?
eng.Rand_surf(narfout=0)
Without seeing the body of the MATLAB function you're trying to call, it's going to be difficult if not impossible to offer any concrete guidance.
아영 박
아영 박 il 5 Set 2024
That was indeed a typo. Thanks for pointing it out.

Accedi per commentare.

Risposte (1)

Kanishk
Kanishk il 5 Set 2024
Hi,
Adding on to Steven’s comment, “narfout” is indeed a typo which should be “nargout”. In addition to this there is also another issue with the usage of “gamma” function in MATLAB script.
The “gamma” function is used which supports input types of “double” and “single”. However, the variable “W_b” in the Python script is initialized as an integer, resulting in an int64 data type in MATLAB, which is not compatible with the gamma function. This results in the error :
matlab.engine.MatlabExecutionError
Undefined function 'gamma' for input arguments of type 'int64'.
To resolve this issue, you can either use “matlab.double” to explicitly convert the variable or initialize “W_b” as a float in Python, which will result in a double type in MATLAB.
WB_b = matlab.double(2)
or
WB_b = 2.0
Please go through the official MATLAB documentation of passing data types from Python to MATLAB to know more about data type mapping.
Hope this helps!
Thanks

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by