フィルターのクリア

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 Center および File ExchangeLanguage Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by