且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MATLAB命令(从庆典/命令行)在一个已经运行的会话

更新时间:2023-01-15 19:24:12

我会建议一个类似的解决方案,为的 carandraug 的那样,只有我preFER TMUX 作为多路复用器。它可能是一个有点棘手得到正确地使创建一个shell脚本处理的细节传递的命令。

I would suggest a similar solution as carandraug did, only I prefer tmux as the multiplexer. It may be a bit tricky getting the commands passed in correctly so create a shell-script that handles the details.

假设你已经在这样的终端启动 MATLAB

Let's say you've started matlab in a terminal like this:

tmux new -s matlab "matlab -nodesktop -nojvm"

现在所谓的matlab一个 TMUX 会话运行MATLAB,没有图形用户界面。

Now a tmux session called matlab is running matlab with no gui.

创建此shell脚本:

Create this shell-script:

MX

#!/bin/bash

if [[ $# -eq 0 ]]; then
  while read; do
    tmux send-keys -t matlab "$REPLY"$'\n'
  done
else
  tmux send-keys -t matlab "$@"$'\n'
fi

在不同的终端,你就可以执行引述MATLAB命令:

In a different terminal you can now run quoted matlab commands:

mx "A = reshape(1:9, 3, 3)"

甚至可以通过管道传递命令:

Or even pass commands in through a pipe:

for mat in A B C; do echo "$mat = reshape(1:9, 3, 3)"; done | mx