フィルターのクリア

How do I move a Matrix from Command Window to Editor?

6 ビュー (過去 30 日間)
George
George 2012 年 9 月 15 日
I made a matrix N in command window that I want to use in Editor. How do I move the data from command window to something I use in Editor. I just didnt want to copy and paste, and have to manually semicolon each row. Its a big matrix.

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 15 日
編集済み: Azzi Abdelmalek 2012 年 9 月 15 日
save filename N % in matlab command
load filename % in matlab editor
%or
y=load('filename') ;% in matlab editor
N=y.N

Jan
Jan 2012 年 9 月 15 日
編集済み: Jan 2012 年 9 月 15 日
When I understand you correctly, you have a matrix as a variable in the command window and want to get the corresponding code.
function MatrixToClipboard(X, F)
Fmt = '%g'; % Adjust this to your needs
[s1, s2] = size(X);
Xt = transpose(X);
FmtV = [repmat([Fmt, ', '], 1, s2 - 1), Fmt];
S = ['[', sprintf([FmtV, '; ...\n'], Xt(:, 1:s1 - 1)), ...
sprintf([FmtV, '];\n'], Xt(:, s1))];
clipboard('copy', S);
Now call this from the command window:
X = rand(4, 5); % test data
MatrixToClipboard(x)
Finally press Strg-V in the editor to get:
[0.814724, 0.126987, 0.632359; ...
0.905792, 0.913376, 0.0975404];
  1 件のコメント
Peter Scotson
Peter Scotson 2012 年 9 月 18 日
clipboard('copy', mat2str(X)); does something similar.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by