Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delete only one line in command window

2,949 views
Skip to first unread message

hzab...@gmail.com

unread,
Apr 9, 2008, 6:07:15 AM4/9/08
to
Hi,
I am looking for the way to delete only one line of the command
window.
If I use "clc" it will delete all output from the file so I have to
plot everything again.
If I user sprintf I need to know the exact number of \b I have to put
in order to delete.

the application is to write the console output in case of a double for

---------------------------
code------------------------------------------------------
for Counter1=1:10
disp(['Counter 1 (main) ' num2str(Counter1) ' of 10'])
for Counter2=1:10
disp([num2str(Counter2) ' of 10']) %I want to rewrite this
line each time. Keeping the Counter1 display.
pause(0.1)
end
end

---------------------------end
code-----------------------------------------

the output I want to achieve is the same as this one, but in my
application the "second for" is inside a function and I do not have
the information to display the "counter 1"

---------------------------
code------------------------------------------------------
for Counter1=1:10
for Counter2=1:10
clc
disp(['Counter 1 (main) ' num2str(Counter1) ' of 10'])
disp([num2str(Counter2) ' of 10']) %I want to rewrite this
line each time. Keeping the Counter1 display.
pause(0.1)
end
end
-----------------------end
code-----------------------------------------------------

Jerome Briot

unread,
Apr 9, 2008, 7:51:03 AM4/9/08
to
Hi,

try this :

for Counter1=1:10

fprintf('Counter 1 (main) %d of 10\n',Counter1);

fprintf(' 0 of 10');

for Counter2=1:10

fprintf('%c%c%c%c%c%c%c%c%2d of
10',8,8,8,8,8,8,8,8,Counter2)
pause(0.1)
end

fprintf('\n')

end

Jerome (Dut)

Haritz Zabaleta

unread,
Apr 10, 2008, 8:53:02 AM4/10/08
to
Thanks for the idea,

I was looking for some command like "clcl" clear command
line or something, but this also helps.

Thanx,

Haritz

Frank Manni

unread,
Sep 13, 2008, 6:52:01 AM9/13/08
to
"Haritz Zabaleta" <hzab...@fatronik.com> wrote in message <ftl2je$9ea$1...@fred.mathworks.com>...

Have you found, since then, any other way of deleting single lines or some lines in the command windows without using fprintf command??
It's only a few days since I have come back to matlab and I am writing sample programs to review m language.
I need to update two counters on two different, consecutive lines.
I am sure it can be done exploting the code up here in this post but I need some help.

Thanks in advance

Rune Allnor

unread,
Sep 13, 2008, 9:07:38 AM9/13/08
to
On 13 Sep, 12:52, "Frank Manni" <francesco.mann...@fastwebnet.it>
wrote:

> Have you found, since then, any other way of deleting single lines or some lines in the command windows without using fprintf command??

I can't think of a single reason why that sort of thing would be
useful.

> It's only a few days since I have come back to matlab and I am writing sample programs to review m language.
> I need to update two counters on two different, consecutive lines.
> I am sure it can be done exploting the code up here in this post but I need some help.

If you are running the same set of commands over and over then
write a script. If you run the same set of commands with different
parameteres write a function.

Rune

Kim Bostroem

unread,
Mar 16, 2011, 6:41:04 AM3/16/11
to
Hi Jerome,
why does this work, actually? What is character 8?
best,
Kim
"Jerome Briot" wrote in message <ftiaj7$bkk$1...@fred.mathworks.com>...

Lucas

unread,
Sep 12, 2012, 4:19:08 AM9/12/12
to
Character 8 in ASCII is for Backspace. That's why it works.

"Kim Bostroem" wrote in message <ilq440$eht$1...@ginger.mathworks.com>...

kasimt...@gmail.com

unread,
Dec 12, 2013, 5:09:14 AM12/12/13
to
Hi,

I use 'dispstat' function just for this purpose. It can update the previous output which is a missing function of default 'disp'. Very simple to use. It can be downloaded from here: http://www.mathworks.com/matlabcentral/fileexchange/44673-overwritable-message-outputs-to-commandline-window

***Sample usage:
dispstat('','init'); % One time only initialization
dispstat(sprintf('Begining the process...'),'keepthis','timestamp');
for i = 97:100
dispstat(sprintf('Progress %d%%',i),'timestamp');
%doing some heavy stuff here
end
dispstat('Finished.','keepprev');

***Output:
11:25:37 Begining the process...
11:25:37 Progress 100%
Finished.

All the best,
Kasim Tasdemir
0 new messages