How to know where the >> are in the command window?

I would like to know if there is a matlab command to know where the '>>' will be at the end of a function execution.
For example if I do
fprintf('AAAAAAAAAAAAAAA')
I will get on the next command line
AAAAAAAAAAAAAAA>>
The '>> ' are in the different position than the default position when I open Matlab. Is there a way to get where that position is?
Thanks

4 Comments

"Is there a way to get where that position is?"
Not trivially, as it depends on the characters printed, including backspace and newlines...
What do you want this for?
Sometimes (not always) a function will display a message. Because that function is in a forloop, the message will be duplicated. I don't want to use the '\n' because I don't want to pollute my screen with the same message n times (so n lines). n can vary between 1 and 0.5million.
I would like at the end of my forloop to check where the position of the chevron >> would be (this depends if a message was displayed or not and of the number of times the message was displayed inside the forloop). If no message is displayed, the chevron >> would be at a start of a line, thus I don't want to do anything. If a message (or several) was (were) displayed, I want to put back the chevron >> at the beginning of the line.
Thanks
There is no trivial way to do this once the strings have been printed.
The simplest approach is to keep track of this yourself, by adding a flag to your code that indicates if that particular message has been printed or not.
Thanks for your answer, I'll see how I can add a flag inside my code.

Sign in to comment.

Answers (1)

Just use
fprintf('AAAAAAAAAAAAAAA\n')
instead and it will put the new line at the end so that the >> will be on the next line where you expect it to be.

1 Comment

The original posted has said in a comment above:
"I don't want to use the '\n' because I don't want to pollute my screen with the same message n times (so n lines). n can vary between 1 and 0.5million."

Sign in to comment.

Asked:

on 19 Dec 2019

Commented:

ME
on 19 Dec 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!