Disp()将自动开始一个新行,所以要在一行中打印所有内容,您需要使用s/fprintf(),在一个表达式中。你的close,你只需要删除disp线并将fprintf表达式替换为:
流(' t\t %i %i %i %f \n',矩阵(i,:), avg);
有关打印数组的更多细节可以在//www.tatmou.com/matlabcentral/answers/333890-how-do-i-use-fprintf-to-show-the-entire-array-in-one-ouput-statement上找到