카테고리
Course Basiccourse-basic
코드와 해설을 함께 읽는 학습 문서
Code Detail
Core Octave 중심의 Octave 학습 예제
course/basic/hist_wsg.m
코드를 복사해 Octave에서 바로 실행할 수 있습니다.
function [counts, bins] = hist_wsg(x, n)
29 lines
function [counts, bins] = hist_wsg(x, n)
# input:
# x: series data
# n: number of bins
#
# output:
# counts: number of data in each bin
# bins: bin edges
nx = length(x);
x_min = min(x);
x_max = max(x);
dx = (x_max - x_min) / n;
bins = x_min:dx:x_max; % (1, n+1) bin edges or poles
counts = zeros(1, n);
for i = 1:nx
for j = 1:n
if x(i) >= bins(j) && x(i) < bins(j+1)
counts(j) = counts(j) + 1;
end
end
end
bins = bins(1:end-1); # (1, n) fenses
end