필터 지우기
필터 지우기

Drawing using if function

조회 수: 2 (최근 30일)
Lina Alhelo
Lina Alhelo 2022년 9월 14일
댓글: Jan 2022년 9월 15일
Hi all;
I would like to generate drawing (graph) for Y and X when ever N value is Yes . Can you help me in writting the code
  댓글 수: 3
Lina Alhelo
Lina Alhelo 2022년 9월 14일
Thank you Jan,
Y is the vehicle speed, X is the time min interval, and N is the indication if there is an accident or not (if there is it will be written as Yes in the row)
Jan
Jan 2022년 9월 15일
@Lina Alhelo: For Matlab X, Y and N are arrays of a certain type. It does not matter, if they represent vehicles, US$ or intergalactic spaceships. But it does matter, if they are ouble vectors, cell strings, string arrays, etc. and what values they have. Therefore a short explicit example of input data is more useful than explaining the physical meaning of the variables.

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

채택된 답변

Walter Roberson
Walter Roberson 2022년 9월 14일

추가 답변 (1개)

vamshi sai yele
vamshi sai yele 2022년 9월 14일
Hi Lina,
I understood that, based on the 'N' condition, you want to communicate whether accident took place or not. I have tried from my end and below is the solution for the same. I made the below code from my understanding towards this question.
In the code depending upon the 'N' value initially, the "if" condition displays a graph or a message. In this test case, I have tried to display the "cos" graph when the condition is satisfied. In your project kindly set up the required graph. Also note that, saying "Yes" is same as "True" and logical value "1" [Yes==True==1].
N = 1
if N == 1
Accident()
else
display("No accident, everyone are safe")
end
function Accident()
f=5;
time=2;
Ts=1/100;
t=Ts:Ts:time;
x=(cos(2*pi*f*t));
plot(t,x)
end
For detailed information and for other case implimentations on "if" condition, refer to this link
Hope I have addressed your question and you find it helpful!

Community Treasure Hunt

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

Start Hunting!

Translated by