histogram2​で得た頻度分布図から​度数値に係数掛けをし​て二次元マップとして​流用したい

12 views (last 30 days)
和也
和也 on 29 Jul 2022
Answered: Shunichi Kusano on 1 Aug 2022
histogram2を利用すると2変量の度数分布図が得られます。
この度数1あたりの変化量、例えば 0.1sec/1度数を度数に掛けると度数分布図から経過時間を得られると思います。
どのようにすればよいでしょうか?
詳しい方よろしくお願いします。

Answers (1)

Shunichi Kusano
Shunichi Kusano on 1 Aug 2022
h = histogram2(...)で出てきたハンドルhの中に度数データがあるので、これを上書きして…とおもったら書込み専用でだめでした。
x = randn(10000,1); % ダミーデータX
y = randn(10000,1); % ダミーデータY
h = histogram2(x,y)
h =
Histogram2 with properties: Data: [10000×2 double] Values: [27×28 double] NumBins: [27 28] XBinEdges: [-4.5000 -4.2000 -3.9000 -3.6000 -3.3000 -3.0000 -2.7000 -2.4000 -2.1000 -1.8000 -1.5000 -1.2000 -0.9000 -0.6000 -0.3000 0 0.3000 0.6000 0.9000 1.2000 1.5000 1.8000 2.1000 2.4000 2.7000 3 3.3000 3.6000] YBinEdges: [-4.2000 -3.9000 -3.6000 -3.3000 -3.0000 -2.7000 -2.4000 -2.1000 -1.8000 -1.5000 -1.2000 -0.9000 -0.6000 -0.3000 0 0.3000 0.6000 0.9000 1.2000 1.5000 1.8000 2.1000 2.4000 2.7000 3 3.3000 3.6000 3.9000 4.2000] BinWidth: [0.3000 0.3000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0.1500 0.1500 0.1500] Show all properties
c = 0.01; % 変換のための係数
h.Values = h.Values * c; % h.Valuesに上書きができず、エラーとなる。
Unable to set the 'Values' property of class ''Histogram2'' because it is read-only.
ここはhistogram2にちょうどいい構文があるので、これを使って描画するデータそのもの(hから流用)を入れてあげます。
% 上のh.Values = h.Values * c; を下のコマンドに置き換える
h2 = histogram2('XBinEdges',h.XBinEdges,'YBinEdges',h.YBinEdges,'BinCounts',h.BinCounts*c) % *cで変換した度数を入力できます

Tags

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!