Open .m files in current MATLAB instance from Windows Powershell

조회 수: 6 (최근 30일)
Mitsu
Mitsu 2021년 9월 25일
편집: Mitsu 2021년 9월 26일
I am trying to open matlab files via matlab file.m from Windows PowerShell, so that I can proceed to edit them in MATLAB. However, when I run that, it starts a new instance of MATLAB.
What changes should I make in my computer/shell so that the above command opens the .m file in the existing MATLAB instance?
Ideally, I would like the changes to be permanent, and not have to write additional commands or flags every time I start a new instance of the PowerShell and wish to open an .m file.
Before upgrading to 2019a, I was used to just running matlab C:/Users/username/Documents/script_to_edit.m on PowerShell, and it would open in the instance of MATLAB that I had already open. Now, when I do that, it opens a new instance of MATLAB instead. I suppose it has to do with paths and/or aliases that were removed during the upgrade.

답변 (1개)

Ive J
Ive J 2021년 9월 26일
Try this
function addME(a, b)
fprintf("sum a + b equals %.2g\n", a + b)
end
Then from powershell (assuming your PS instance is within pwd):
matlab -batch "addME(3, 5)"
  댓글 수: 3
Mitsu
Mitsu 2021년 9월 26일
편집: Mitsu 2021년 9월 26일
Sorry, I failed to clarify it better.
I do not want to run a script from the terminal; I do not want to do anything on the terminal other than opening the file with the MATLAB editor.
Usually:
  1. I am editing code using MATLAB's GUI
  2. I need to make changes to some other file but don't know its location; I use grep, find, etc to find the file on the promp
  3. I typed matlab example_file.m
  4. The file is opened in the existing instance of MATLAB, and I edit it
This is different from the two questions in the links.
Additionally, I was able to do this when I was using MATLAB 2018b (more recent than the versions discussed in the links) . When upgrading to R2019a, the removal of preferences might have disabled this.

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

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by