How to print in the same line
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Grzegorz Knor
2011년 9월 28일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!