Using Matlab to open a text file
30 次查看(过去 30 天)
显示 更早的评论
Hi all,
Running MacOS Mojave and have set the default terminal to ZSh (I think!)
I've a script that returns a list of text files in cell format and want to give user the option to open (some of) them.
Without Matlab, I navigate to the folder and open the text file by double clicking. With me here?! This opens the file in Sublime Text (or other text editer, but ST is my chosen default). Alternatively, I could use the Mac OS terminal to open it... Lets build the story here - sorry to those who already know this stuff.
I can use the terminal to open Sublime Text (or other application that exists) by typing
subl
(or whatever application I want to open) into the command window.
I can open a specified text file from the terminal window in a similar way by typing
subl NameOfTextFile.txt
I'm wanting to essentially have Matlab do this, by essentially running
system('subl NameOfTextFile.txt')
but as seen when I run as follows:
system('subl NameOfTextFile.txt')
/bin/bash: subl: command not found
ans =
127
I can successfully run other system commands from the Matlab command window, for example
system('sleep 4')
will pause the command window for 4 seconds, so I know that things 'should' work if correctly set, but obviously I'm not setting things correctly somewhere.
I've also tried
unix('subl NameOfTextFile.txt')
/bin/bash: subl: command not found
ans =
127
but as seen, same issue. The 'unix('sleep 4')' also works as I'd expect.
Is the issue with my chosen system shell (zsh rather than bash) in which case, how can I set it to work, or something else?
TIA
0 个评论
采纳的回答
Benjamin Thompson
2022-7-14
Looks like subl is not in your search path. You can use the system command to print out the search path that the MATLAB process sees. If it is not there, then add it. I don't use UNIX so I don't know the specific commands for that.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!