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