[Python] Inputting variables when running python code in MATLAB using system

Discussão em 'Python' iniciado por Stack, Janeiro 22, 2025.

  1. Stack

    Stack Membro Participativo

    I have this part of my MATLAB script where im trying to run a python code:

    %%% MATLAB %%%
    system(sprintf('python "%s" "%s" "%s"', 'Merge_CT_MRI_targets.py', num2str(OriginalPatients(index_target)), num2str(target_list(index_target))));
    disp('test1')


    This is the python script:

    ### PYTHON ###
    import itk
    import numpy as np
    import os
    import time

    MRI_target = itk.imread("MRI_"+target+"_"+originalPatient+".nii", itk.F)


    However, it looks like the variables aren't being properly called in the python script:

    % matlab command window %
    Traceback (most recent call last):
    File "Merge_CT_MRI_targets.py", line 23, in <module>
    MRI_target = itk.imread("MRI_"+target+"_"+originalPatient+".nii", itk.F)
    ^^^^^^
    NameError: name 'target' is not defined


    Any help is appreciated. I previously tried using pyrunfile but it also brings an error.

    Continue reading...

Compartilhe esta Página