What does this command (x = [(n-n0) >= 0];) do in the following code?

조회 수: 4 (최근 30일)
Troy
Troy 2015년 3월 17일
댓글: Troy 2015년 3월 17일
funtion[x,n]=stepseq(n0,n1,n2) n=[n1:n2]; x=[(n-n0)>=0];

채택된 답변

Anusha B
Anusha B 2015년 3월 17일
Assuming n0 is a scalar and n is a vector of numbers, the statement x=[(n-n0)>=0;) will create a logical vector 'x' that will contain values of '1' and '0's based on the result of the operation (n-n0)>=0;
For example, if n0=3 and n=[1 2 3 4 5]
x=[(n-n0)>=0] will cause the vector 'x' to have the following values
x= [ 0 0 1 1 1]
Hope this helps.

추가 답변 (1개)

Anusha B
Anusha B 2015년 3월 17일
Assuming n0 is a scalar and n is a vector, the statement x=[(n-n0)>=0]; will create a logical vector 'x' that will contain values '1's or '0's based on the result of the operation (n-n0)>=0. If the condition is true for a vector element, the value returned is 1. Otherwise 0 is returned.
For example:
n0=3; n=[1 2 3 4 5]; x=[(n-n0)>=0]; % This will cause the x to have the values [0 0 1 1 1]
Hope this helps.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by