我有两个文件,第一个是主文件,它调用第二个文件。因此,在运行第一个文件时,我想输出在第二个文件中创建的矩阵,也许可以通过主文件中的printf输出?
我已经尝试过这种方法,但没有成功,而且显示的是行而不是列:
我已经尝试过这种方法,但没有成功,而且显示的是行而不是列:
printf("[%f; %f; %f]\n",r)
如果你想要调试输出(尤其是在循环内部),你需要先使用more off
命令关闭分页,然后使用disp(当然你需要在这里添加你的矩阵名称)
或者只是提及变量而不加分号,或者在赋值时去掉分号。
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
Then from your octave terminal, run the 'master.m' script:
master
This will display the contents of A
on screen.
disp(yourmatrix)
简单地输出矩阵。 - Andydisp(yourmatrix)
,但没有成功... 我只想打印矩阵以进行调试... - isk27