How to grab message from command window and take action in code depending on it.

How to check command window output and performe action depending on it.
for k = 1:500;
z=z+1;
check(z); %% check.p file checking z and gives output in command window
%% code that should breake the code if command window throws "z is correct"
end

2 Kommentare

What command do you want to check?
I dont want to check anny command check is file name, that brings some output depending on z value

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 8 Okt. 2019
I'm almost certain you do not want to do what you asked. It's bizarre. Why not just write a normal program with a GUI or an inputdlg() to ask the user for some input? Or if it was something printed/echoed to the command window by a line of code in your program, just send that line directly to whatever other code needs it.

6 Kommentare

part of code that echoed to command window has encripted and i have no access to it. I am traying to check all possible values of z. Answer is given in command window. When it hapens i want brake further execution.
Well you could turn the "diary" function on to save all command window stuff to a file, then when you need to check it you could open the file and search for what you need to find.
Sometime there may be 100 millions of itterations. I need perform this action multiple times with multiple variables. That is why loop need to be stoped. If loop cannot be stoped, maybe turning diary off in certain point is an option?
You can turn it off and on at anytime with the diary command.
I need to determin moment when to turn it off depending on command window output, how to include it in code?
Open the diary file and search for the stopping condition with strfind() or endsWith(). If you find it, turn the diary off. Then since no diary will be continued I guess you'll have to determine somehow in your code when to start logging output to the diary again.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Debugging and Analysis finden Sie in Hilfe-Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by