substitute for discretize command

discretize function was available in new version of matlab..but i have older version (R2014b)in my desktop. i cannot install new version into my desktop..please help my with an alternative function for discretize in matlab

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 11 月 18 日

0 投票

For equal intervals, separated by delta:
discrete_x = floor( (x - minimum_allowed_x) ./ delta ) .* delta + minimum_allowed_x;
For unequal intervals in which the left edges are given by the vector edges and the last entry of edges is the upper bound:
[~, ~, bin] = histcounts( x, edges );
discrete_x = edges(bin);

5 件のコメント

Iason Grigoratos
Iason Grigoratos 2016 年 12 月 20 日
編集済み: Iason Grigoratos 2016 年 12 月 20 日
matlab 2014a does not have histcounts. Any alternatives?
I did the following:
data = [1 1 2 3 6 5 8 10 4 4]
binedges = 2:2:10;
[cnt, idx] = histc( data, binedges );
outside = data(idx==0) % data that fall outside the bins
binned(1) = data(idx==1) % data that fall into the first bin (2 to 4)
binned(2) = data(idx==2) % data that fall into the first bin (4 to 6) % and so on
% for data value equal to 10 is doesnt work properly though
Walter Roberson
Walter Roberson 2016 年 12 月 20 日
[~, bin] = histc( x, edges );
discrete_x = edges(bin);
Iason Grigoratos
Iason Grigoratos 2016 年 12 月 20 日
編集済み: Iason Grigoratos 2016 年 12 月 20 日
it does not work properly, example:
x = [1 1 2 3 6 5 8 10 4 4];
edges = 2:2:10;
[~, bin] = histc( data, edges );
discrete_x = edges(bin);
% bin takes the value of "5" when data value is "10", while the bins are 4 (N border values, N-1 bins)
-- can i just do "bin(bin>=length(edges))=length(edges)-1" ?
Also if x is outside the edges then edges(bin) returns an error, so your x must always be within the range of bins.
Walter Roberson
Walter Roberson 2016 年 12 月 20 日
[~, discrete_x] = histc(x, edges);
discrete_x(discrete_x == length(edges)) = length(edges)-1;
discrete_x(discrete_x == 0) = NaN;
johnson saldanha
johnson saldanha 2018 年 11 月 6 日
may i know how can i be able to get the 2nd column from the x matrix in discrete_x

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2016 年 11 月 18 日

コメント済み:

2018 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by