class1234
class1234

Reputation: 59

print in single line in matlab command line

how to print to Command line in Matlab. which all output print statements will be in single line.

for example,

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

OUTPUT: 1234

Not:

1

2

3

4

Upvotes: 2

Views: 1859

Answers (1)

Dan
Dan

Reputation: 45762

An option using fprintf

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

And if you want linebreaks at specific points use the \n escape sequence and also it allows you to some formatting such as spacing:

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

Upvotes: 4

Related Questions