フィルターのクリア

how do i discretize negative integers

1 回表示 (過去 30 日間)
johnson saldanha
johnson saldanha 2018 年 11 月 6 日
編集済み: Bruno Luong 2018 年 11 月 12 日
[~, discrete_x] = histc(x, edges);
discrete_x(discrete_x == length(edges)) = length(edges)-1;
discrete_x(discrete_x == 0) = NaN;
This works for positive integers only. what do i do if i have to do it for negative integers?

採用された回答

Stephen23
Stephen23 2018 年 11 月 6 日
編集済み: Stephen23 2018 年 11 月 6 日
"This works for positive integers only"
Actually histc works perfectly for negative values. It works for me:
>> x = 4-randi(9,1,10)
x =
-2 -5 -5 1 -1 -5 1 1 2 0
>> edges = -6:4:6
edges =
-6 -2 2 6
>> [~, idx] = histc(x, edges)
idx =
2 1 1 2 2 1 2 2 3 2
>> vec = x(idx)
vec =
-5 -2 -2 -5 -5 -2 -5 -5 -5 -5
  38 件のコメント
johnson saldanha
johnson saldanha 2018 年 11 月 12 日
@StephenCobeldick. im getting the answer as 20. thats it
Bruno Luong
Bruno Luong 2018 年 11 月 12 日
編集済み: Bruno Luong 2018 年 11 月 12 日
So? Common: YOU make a change (column #2) that breaks the code, so don't complain to me.

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

その他の回答 (1 件)

Bruno Luong
Bruno Luong 2018 年 11 月 6 日
"This works for positive integers only."
Wrong claim. It works for negative numbers,
histc(-1.5,[-3 -2 -1])
ans =
0 1 0
It only edges to be increased, meaning decrease in the absolute values
  1 件のコメント
johnson saldanha
johnson saldanha 2018 年 11 月 12 日
after i am done assigning how do the display the values in each bin

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by