Using Matlab to open a text file
30 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Benjamin Thompson
le 14 Juil 2022
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.
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!