Matlab 會話(sessions)多開,運行多個程序

matlab R2012a 之後提供了會話多開功能,可以開多個會話,但是每個會話的佔用內存都和原來一樣多,運行前請先預留內存空間。

可以用這個功能建立服務機和客戶機通信,調試程序等等。

本文中給出TCP 服務器和客戶機通信示例。


1.找到matlab安裝目錄;

unix:應用程序中找到matlab-右鍵(顯示包內容)-bin-matlab
windows: 安裝目錄-bin-matlab


2.製作替身/快捷方式
製作替身


3.運行替身/快捷方式
在已經打開matlab的基礎上,運行快捷方式,可以看到運行了兩個matlab程序(要開多個類似)
這裏寫圖片描述


4.Server

這裏給出mathwork support team給的簡單通信例子;
一個會話運行Server,另一個會話運行Client

t = tcpip('0.0.0.0', 30000, 'NetworkRole', 'server');
%Open a connection. This will not return until a connection is received.

fopen(t);
%Read the waveform and confirm it visually by plotting it.

data = fread(t, t.BytesAvailable);
plot(data);

5.Client

%Create a waveform and visualize it.

data = sin(1:64);
plot(data);
%Create a client interface and open it.

t = tcpip('localhost', 30000, 'NetworkRole', 'client');
fopen(t)
%Write the waveform to the server session.

fwrite(t, data)

6.運行結果
這裏寫圖片描述


補充:
關於更詳細的Socket通信可以訪問mathworks
關於matlab會話多開的想了解matlab團隊的答案的可以訪問MathWorks Support Team

發佈了56 篇原創文章 · 獲贊 53 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章