필터 지우기
필터 지우기

I am trying to make a piecewise vector and have 10001 input values and should be getting 10001 output values, but am only getting one output value

조회 수: 1 (최근 30일)
I am making a piecewise vector. I have 10001 t values and want to have the corresponding 10001 position values, but for some reason when I run the script I only get one position value. Does anyone know why this is happening and what I should do to fix it?
Here is my script:
t=-5:0.001:5; %time in milliseconds (ms)
if t<=-1; %ms
position=-t; %position in feet
elseif (t>-1)&(t<=1); %ms
position=t.^2; %ft
else 1<t; %ms
position=sin(t-1)/(t-1);%ft
end

답변 (1개)

Walter Roberson
Walter Roberson 2020년 2월 2일
t = vector
position = zeros(size(t))
mask = t<=-1
position(mask) = -t(mask) ;
mask = t>-1&t<=1;
position(mask) = t(mask).^2 ;
And so on

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by