How to convert python __name__ = '__main__' into MATLAB ?

if __name__ == '__main__':
undistorb_images(None, None)

댓글 수: 2

Please someone help me.
Have a read here and here. It will greatly improve your chances of getting an answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

Yongjian Feng
Yongjian Feng 2021년 7월 24일
Not sure about what you really want.
For python code,
if __name__ == '__main__':
it means your python script is running as the main program by the python interpreter (as opposite to being imported by some other python scripts).
This is equivalent to a separate matlab script that calls the first matlab script.

댓글 수: 5

Thank you for your response.
Actually I want to convert this main function into MATLAB. How can I do this? Is there any main function in matlab like __name__ == '__main__'
This is my python code:
if __name__ == '__main__':
undistorb_images(None, None)
Which 'this main function'? If you explain the intended behavior, we might be able to recommend a suitable equivalent in Matlab.
Do it in another matlab script.
Matlab script 1, your script with the implementation of undistorb_images:
function undistorb_images(a, b)
% All your logic
end
Matlab script 2, put your "python main function" here for matlab
% Save this script as do_undistorb_images.m
undistorb_images([], []); % matlab doesn't have None,
These two together are then similar to your python script:
# undistorb_images.py
def undistorb_images(a, b):
# All your logic
if __name__ == '__main__':
undistorb_images(None, None)
end
In python you do to run your main function
python undistorb_images.py
For matlab, you do this from the command line window
do_undistorb_images
This will call your undistorb_images.
Thank you so much sir
Accept the answer please if this fix the problem, then others know how to fix it.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 7월 24일

댓글:

2021년 7월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by