How to create a sequence of intervals

3 ビュー (過去 30 日間)
Bilal
Bilal 2024 年 10 月 7 日
編集済み: Walter Roberson 2024 年 10 月 7 日
If my data is y= 2,-3,4,-1,6 and my x=-4. is it possible to obtain a sequence of intervals as follows:
intervalle(1)= [-abs(x-y(1)),abs(x-y(1))], intervalle(2)= [-abs(x-y(2)),abs(x-y(2))]
%... I tried the code:
y=[2 -3 4 -1 6];
x=-4;
n=length(y);
intervalles=[-abs(x-y),abs(x-y)];
for k=1:n
intervalles(k)=[-abs(x-y(k)),abs(x-y(k))];
end

回答 (1 件)

Voss
Voss 2024 年 10 月 7 日
y=[2 -3 4 -1 6];
x=-4;
intervalles=abs(x-y).*[-1;1];

Each column of intervalles contains one interval, accessed by indexing intervalles as follows

intervalles(:,k) % get the kth interval

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by