transplant icon indicating copy to clipboard operation
transplant copied to clipboard

When I use 'transplant.Matlab()' to start up Matlab session , how could I use python code to clase the Matlab session?Now I need to close the window manually. Thanks so much!

Open chaohcc opened this issue 3 years ago • 15 comments

chaohcc avatar Jan 15 '21 11:01 chaohcc

I use python code: matlab.close(); matlab.exit(); matlab.send_message('die'), it seems does't work. Thank so much!

chaohcc avatar Jan 15 '21 12:01 chaohcc

Can you describe your problem in a bit more detail and provide some example code so we can reproduce it?

bastibe avatar Jan 15 '21 12:01 bastibe

Can you describe your problem in a bit more detail and provide some example code so we can reproduce it?

Thank you!
import transplant matlab = transplant.Matlab() res = matlab.Myfun(data,para) Y = res[0] A= res[1] the code above is run correct,and start a matlab session, and run my matlab function "Myfun(data,para)", and return the result of matlab to python. My question is how should I use code or command in python to close the matlab session? Now the matlab session can't close itself, I need close it's window manually, and if the matlab session didn't close, the python code after the matlab session will not run. In other words, the code, Y = res[0] A= res[1] would run after I close the matlab session manually. Sorry, my English is poor, hope I have made it clearly, thank you!

chaohcc avatar Jan 16 '21 01:01 chaohcc

If I understand you correctly, your Myfun does not return? That would be a problem in Myfun, not Transplant.

However, you say "I need to close its window manually", which implies that you are doing graphical things inside Myfun. This can be tricky within Transplant, as Transplant does not / can not drawnow every so often, which some Matlab code requires. You can try adding a few drawnow() to your Myfun and see if that helps.

bastibe avatar Jan 20 '21 19:01 bastibe

If I understand you correctly, your Myfun does not return? That would be a problem in Myfun, not Transplant.

However, you say "I need to close its window manually", which implies that you are doing graphical things inside Myfun. This can be tricky within Transplant, as Transplant does not / can not drawnow every so often, which some Matlab code requires. You can try adding a few drawnow() to your Myfun and see if that helps.

Thank you! my problem is my python code start matlab successfuly and open a matlab window, run Myfun correctly. but python code not continus until the matlab window closed . seems the matlab.exit() methed is not working.

chaohcc avatar Jan 22 '21 08:01 chaohcc

What sort of Matlab window is being opened? Like a figure? What operating system are you running?

bastibe avatar Jan 27 '21 08:01 bastibe

What sort of Matlab window is being opened? Like a figure? What operating system are you running? Thank you! here is the code I start matlab image

I run on Windows10. The opened Matlab window is like the following picture: image

Best wishes! Thank you!

chaohcc avatar Feb 01 '21 09:02 chaohcc

Is that Window interactive, i.e. can you type something in there and get a response? That shouldn't happen.

Could you debug into your transplant_master.py, and report back the value of process_arguments in line 568?

bastibe avatar Feb 03 '21 07:02 bastibe

Is that Window interactive, i.e. can you type something in there and get a response? That shouldn't happen.

Could you debug into your transplant_master.py, and report back the value of process_arguments in line 568?

Thank you! Yes, I can type something in window and it will run and give a response. I debug transplant_master.py, the value of process_arguments : image Thank you!

chaohcc avatar Feb 10 '21 06:02 chaohcc

If there is a window, it should not be interactive. If it is interactive, transplant must have crashed. It's a sad fact of Matlab that some errors can't be caught. Do you see any error messages that might indicate a crash of transplant_remote?

bastibe avatar Feb 10 '21 08:02 bastibe

If there is a window, it should not be interactive. If it is interactive, transplant must have crashed. It's a sad fact of Matlab that some errors can't be caught. Do you see any error messages that might indicate a crash of transplant_remote? Thank you! I haven't see any error messages that might indicate a crash of transplant_remote. Is there any way to see it or debug?

chaohcc avatar Feb 16 '21 12:02 chaohcc

The errors should show up either in your Python console, or in Matlab's window. Although since you seem to be running inside an IDE, perhaps the IDE is eating STDERR?

Perhaps you will see an error if you try running your program in a plain terminal instead of an IDE.

bastibe avatar Feb 17 '21 09:02 bastibe

The errors should show up either in your Python console, or in Matlab's window. Although since you seem to be running inside an IDE, perhaps the IDE is eating STDERR?

Perhaps you will see an error if you try running your program in a plain terminal instead of an IDE. okey, thank you so much, I will have a try running my program in a plain terminal.

chaohcc avatar Feb 19 '21 06:02 chaohcc