How to put conditions to use data from command window

Hello all,
I am using one code and in that code i received output from my program in the Command Window, and i would like to use that output in the same code to apply for condition
Speed= [400 : 100 : 1200] (in the code)
I would like to put the condition in this way
CD= 0.018 (Value directly in the code)
then use CD value in the below condition by using AB and BC value
If AB<CD>BC then successful at speed 10 ,
if above condition not satisfy then unsuccessful at speed 10
Similarly for other different speed as per code (Speed= [10 : 10 : 40] )
If AB<CD>BC then successful at Speed= [10 : 10 : 40]
if above condition not satisfy then unsuccessful at Speed= [10 : 10 : 40]
Thank you so much

7 commentaires

Anybody can help me ? Thank you in advance
Rik
Rik le 19 Jan 2022
Modifié(e) : Rik le 19 Jan 2022
If you are in such a hurry to get an answer you should hire someone. Why did you @ mention a lot of people again? You were told last year not to do that.
To turn to your actual question: it is much easier to do things with the output of a function if you can get to the data directly. Does it print data to the command window? Can you edit the code to return it as data? If not, can you edit the code to write the text to a file?
Sorry @Rik
I am giving the inputs
Speed= [10 : 10 : 40] (in the code)
then middle code of all functions
then
it print like in the command window
Distance (AB, BC) at different speed =
(AB) (BC)
0.0153799925086085 0.0165703972540118 (at 10 speed)
0.0133063614315573 0.0179011999654362 (at 20 speed)
0.0104123522336494 0.0204654384059168 (at 30 speed)
0.00675227349009661 0.0248795773312725 (at 40 speed)
What is the code that results in this text? Can you edit that? You're making it difficult to help you. Have a read here and here. It will greatly improve your chances of getting an answer.
Sorry @Rik , The code is so big, if i write here then you will spent complete day to understand. I don't want to take your complete day , as you need to help other as well. Instead, can you give me syntax to put above condition and receive output as i want in the command window. That would be great help for me.
I would like to put the condition in this way
CD= 0.018 (Value directly in the code)
then use CD value in the below condition by using AB and BC value
If AB<CD>BC then successful at speed 10 ,
if above condition not satisfy then unsuccessful at speed 10
Similarly for other different speed as per code (Speed= [10 : 10 : 40] )
If AB<CD>BC then successful at Speed= [10 : 10 : 40]
if above condition not satisfy then unsuccessful at Speed= [10 : 10 : 40]
then all this successful condition should come in the command window at last
Thank u so much
I don't need the entire code. The point is that there is some code that will print the two number to the command window. If you edit that part of the code so that it returns the two values as output arguments, you can do the conditional part next yourself.
Note that a<b>c means something else in Matlab than it does in normal Mathematics. You need (a<b) && (b>c) instead.

Connectez-vous pour commenter.

Réponses (1)

Assuming that CD is a scalar, and that AB and BC are column vectors and that Speed is a row vector:
statuses = ["unsuccessful", "successful"};
mask = AB < CD & AB > BC;
status = statuses(mask+1);
results = compose("%20.17f %20.17f (%s at %g speed)", AB, BC, statuses, Speed(:))

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by