Filter löschen
Filter löschen

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 Ansicht (letzte 30 Tage)
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

Antworten (1)

Walter Roberson
Walter Roberson am 2 Feb. 2020
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

Kategorien

Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by