How to print in the same line
6 views (last 30 days)
Show older comments
I want to print a pattern on the command window as below
********
********
********
********
********
********
********
********
But Its not working as the line get changed on every execution of inner for loop.
So the question is that how to print the result on the same line in matlab command window.
Thanks
clear all
clc
m=2;
for i=1:8
if(m==2)
for i=1:8
disp('*');
end
m=1;
end
if(m==1)
disp(' ')
for i=1:8
disp('*');
end
m=1;
end
end
0 Comments
Answers (1)
Grzegorz Knor
on 28 Sep 2011
Use fprintf instead of disp.
clear all
clc
m=2;
for i=1:8
if(m==2)
for i=1:8
fprintf('*');
end
fprintf('\n')
m=1;
end
if(m==1)
fprintf(' ')
for i=1:8
fprintf('*');
end
fprintf('\n')
m=2;
end
end
0 Comments
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!