Octave Atelier

코드와 해설을 함께 읽는 학습 문서

Code Detail

hist_wsg

Core Octave 중심의 Octave 학습 예제

course/basic/hist_wsg.m

목록으로

코드를 복사해 Octave에서 바로 실행할 수 있습니다.

카테고리

Course Basic

course-basic

코드 길이

29

lines

작성자

-

날짜 정보 없음

패키지

none

pkg load

함수 시그니처

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

코드 해설

목적

  • Core Octave 중심의 Octave 학습 예제

입력

  • 파라미터: x
  • 파라미터: n

출력

  • 반환값: counts
  • 반환값: bins

실행 흐름

  1. 코드 상단부터 순차 실행

핵심 함수

  • bins
  • counts
  • length
  • max
  • min
  • zeros

실습 과제

  • 핵심 함수 bins의 인자를 한 가지 바꿔 결과 변화를 기록해보세요.

같은 카테고리 코드

이전 코드 hex2color 다음 코드 horizontal