Running a MATLAB script from Notepad++

前端 未结 3 1349
野性不改
野性不改 2021-02-06 12:52

Is there a way of running a MATLAB script from Notepad++?

Obviously I have MATLAB installed on my computer. I know you can set a path for Notepad++to run when you hit F5

3条回答
  •  天命终不由人
    2021-02-06 13:51

    This is a usable implementation upon Sam's idea. First, execute MATLAB in automation mode like this.

    matlab.exe -automation
    

    Next, compile and execute this following VB in NppExec plugin. (which is to use MATLAB automation API)

    'open_matlab.vb
    Imports System
    Module open_matlab
        ' connect to a opened matlab session
        Sub Main()
            Dim h As Object
            Dim res As String
            Dim matcmd As String
    
            h = GetObject(, "Matlab.Application")
            Console.WriteLine("MATLAB & Notepad++")
            Console.WriteLine(" ")
            'mainLoop
            while True
                Console.Write(">> ")
                matcmd = Console.ReadLine()
                ' How you exit this app
                if matcmd.Equals("!!") then
                    Exit while
                End if
                res=h.Execute(matcmd)
                Console.WriteLine(res)
            End while
        End Sub
    End Module
    

    Then you'll get a matlab-like terminal below your editor. You can then code above and execute below. type !! to exit the terminal. What it looks like

    Tips: don't use ctrl+c to interrupt the MATLAB command, because it will kill the whole process instead.

提交回复
热议问题