如何在 Octave 中输出矩阵?

How can I output a matrix in Octave?

我有2个文件,第一个是master,调用第二个。 所以,我想输出在第二个文件中创建的矩阵,同时运行第一个文件,我想可能是通过主文件中的 printf?

我试过这种方法但没有用,除了显示行代替列的事实:

    printf("[%f; %f; %f]\n",r)

如果你想调试输出(尤其是在循环内),你首先使用 more off 禁用寻呼机,然后使用 disp(of_course_you_have_to_add_the_name_of_your_matrix_here) 或者只提及变量而不尾随;或删除尾随;在作业中

more off
for k=1:2
  a = rand(2) * k;  # remove trailing ;
  a                 # or mention it without ;
  disp (a)          # or use disp which doesn't show the variable name
endfor

输出

a =

   0.80112   0.53222
   0.48930   0.56336

   0.80112   0.53222
   0.48930   0.56336
a =

   1.30374   1.85382
   0.30519   0.42486

   1.30374   1.85382
   0.30519   0.42486

看到 a 显示了两次:一次有 "a = " 一次没有

在当前文件夹中创建以下文件。

%%% in file: second.m

A = [1,2;3,4];    % adding a semicolon suppresses the output

%%% in file: master.m

% run 'second.m' script - this will add A on the workspace, since
% running this script is as if you had dumped the file's contents here
second    

% call the value of A without a semicolon to show contents on screen
A         

然后从您的 Octave 终端,运行 'master.m' 脚本:

master

这将在屏幕上显示 A 的内容。