在matlab命令行中单行打印

时间:2014-09-19 10:26:04

标签: matlab

如何在Matlab中打印到命令行。所有输出的打印语句都是单行的。

例如,

for i=1:4
   disp(i)     => or others print statement!
end

输出: 1234

1

2

3

4

1 个答案:

答案 0 :(得分:3)

使用fprintf

的选项
for i=1:4
    fprintf('%d',i)
end
fprintf('\n') %//add a line break at the end

如果你想在特定点使用换行符,请使用\n转义序列,并且它还允许你进行一些格式化,例如间距:

for i=1:12
    fprintf('%10d',i)
    if mod(i,3)==0
        fprintf('\n');
    end
end