How to put conditions to use data from command window

조회 수: 1 (최근 30일)
Esila Darci
Esila Darci 2022년 1월 19일
편집: Esila Darci 2022년 1월 25일
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
Esila Darci
Esila Darci 2022년 1월 19일
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
Rik
Rik 2022년 1월 19일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2022년 1월 19일
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(:))

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by