How to display values of an array only in the specified ranges?

3 ビュー (過去 30 日間)
pavan sunder
pavan sunder 2016 年 11 月 2 日
編集済み: KSSV 2016 年 11 月 2 日
i have [1xm] array of values. i want to display the values only in the ranges given in seperate arrays: lowerlimits=[2 6 10] upperlimits=[4 9 12]
the output is again [1xm] with values of array mentioned in the lower and upperlimts the rest should be zero.

回答 (1 件)

KSSV
KSSV 2016 年 11 月 2 日
編集済み: KSSV 2016 年 11 月 2 日
clc; clear al;
m = 100 ;
data = randi([1 50],1,100) ; % random data bewtween 1 and 50
ll = [2 6 10] ; % lower limit
ul = [4 9 12] ; % upper limit
iwant = zeros(size(data)) ; % initialize the array wanted
for i = 1:length(ll) ;
idx = (data>=ll(i) & data<=ul(i)) ; % indices of given range
iwant(idx) = data(idx) ; % replace the indices with the values
end

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by