MATLAB Note/グラフ の変更点
Top / MATLAB Note / グラフ
- 追加された行はこの色です。
- 削除された行はこの色です。
- MATLAB Note/グラフ へ行く。
#freeze
-目次
#contents
**2次元グラフ [#u9508999]
-以下の配列A(([[行列と魔方陣:http://shakosv.sk.tsukuba.ac.jp/ShakoDoc/MATLAB/helpdesk/techdoc/getstart/gets2.htm]]より引用))を使って説明します。
>> A = [16 3 2 13 5 10 11 8; 9 6 7 12 4 15 14 1]
A =
16 3 2 13 5 10 11 8
9 6 7 12 4 15 14 1
-プロット1
>> plot(A)
&ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/plot1.jpg);
-プロット2
>> plot(A')
&ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/plot2.jpg);
-プロット3
>> plot(A(1,:),A(2,:),'o')
&ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/plot3.jpg);
-プロット3-1 以下の配列Bといっしょにプロット
>> B = [1 14 15 4 12 7 6 9; 16 3 2 13 5 10 11 8]
B =
1 14 15 4 12 7 6 9
16 3 2 13 5 10 11 8
>> h = plot(A(1,:),A(2,:),'o',B(1,:),B(2,:),'.');
>> legend(h, 'A', 'B');
&ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/plot3_1.jpg);
***色を指定する [#f214efab]
**3次元グラフ [#k77e1a9e]
-以下の配列A,B,Cを使って説明します。
>> A = [1 2 3; 1 2 3; 1 2 3]
A =
1 2 3
1 2 3
1 2 3
>> B = [1 1 1; 2 2 2; 3 3 3]
B =
1 1 1
2 2 2
3 3 3
>> C = [0 0 0; 1 1 1; 0 0 0]
C =
0 0 0
1 1 1
0 0 0
-3次元サーフェスでプロット
#geshi(matlab){{
set(gcf,'position',[230 259 560 420]);
surf(A,B,C,'FaceColor','interp','EdgeColor','none');
xlabel('A'), ylabel('B'), zlabel('C'), title('3D-plot');
axis tight;
camlight left;
}}
&ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/plot3d.jpg);
**ヒストグラム [#g05d53d5]
-1次元データの分析
--関数HISTを使います。以下はヘルプから転載です。
--N = HIST(Y) は、10 個の等間隔のコンテナに Y の要素を分類し、各コンテナの要素数を出力します。Y が行列の場合、HIST は列に対して機能します。N = HIST(Y,M) は、M がスカラの場合、M 個のビンを使います。
--例えば、
>> A = [1 1 2 3 5 6 7 8 9]
これを1~3, 4~6, 7~9のヒストグラムにしたいとき、
>> N = hist(A,3) %変数Aの中身をM個のビンで分ける
N =
4 2 3
1~3に4個、4~6に2個、7~9に3個の値があることを示しています。
また、
>> hist(A,3)
とすることで、ヒストグラムをプロットします。
-2次元データの分析
--平均値の異なる2つの2次元正規分布の値をプロットして、3次元ヒストグラムで表示する
#geshi(matlab){{
%平均値の異なる2つの2次元正規分布の値をプロット
A = randn(1000,1000) + 4;
B = randn(1000,1000) + 6;
plot(A(1,:),A(2,:),'.',B(1,:),B(2,:),'x'); legend('A', 'B');
data = [A ; B]; %全データをまとめる
%3次元ヒストグラムを作成
% 分析するセルの範囲を定義
xl = 0.5; maxX = 10; %x軸のセルの幅は0.5、最大値は10
yl = 0.5; maxY = 10; %y軸のセルの幅は0.5、最大値は10
% 各セルの中に値が何個入っているかを調べる
frequency = zeros( (maxX/xl)+1, (maxY/yl)+1 );
labelX = zeros((maxX/xl)+1, 1); labelY = zeros((maxY/yl)+1, 1);
countY = 0; countX = 0;
for i2 = 0:yl:(maxY-1) %FOR文 0~(maxY-1)までylおきに処理
countY = countY + 1;
for i1 = 0:xl:maxX %FOR文 0~maxXまでxlおきに処理
countX = countX + 1;
hitData = find( (data(:,1)>(i1)) & (data(:,1)<=(i1+xl)) & ...
(data(:,2)>(i2)) & (data(:,2)<=(i2+yl)) );
hitDataSize = size(hitData);
frequency(countX, countY) = hitDataSize(1);
labelX(countX) = i1; %座標ラベル
end
labelY(countY) = i2; %座標ラベル
countX = 0;
end
% 3次元サーフェスでヒストグラムをプロット
figure(2), set(gcf,'position',[230 259 560 420])
surf(labelY, labelX, frequency, ...
'FaceColor', 'interp', 'EdgeColor', 'none', 'FaceLighting', 'phong');
xlabel('A'); ylabel('B'); zlabel('頻度 (回)'); title('頻度分布');
axis tight; camlight left;
}}
---実行結果は以下のようになります。
#ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/hist1.jpg);
-正規分布を作る
#geshi(matlab){{
rand = rand(10000,5);
randN = sum(rand,2);
hist(randN)
}}
#ref(matlab_graph01.png);
--ヒストグラムのスケールを決めるには、上に続けて、
#geshi(matlab){{
scale = [0 1 2 3 4 5];
hist(randN, scale)
}}
#ref(matlab_graph02.png);
-その他
--HISTFIT 正規確率密度を重ね合わせたヒストグラム [[参考:http://www.mathworks.com/access/helpdesk/help/toolbox/stats/index.html?/access/helpdesk/help/toolbox/stats/histfit.html&http://www.mathworks.com/cgi-bin/texis/webinator/search/?db=MSS&prox=page&rorder=750&rprox=750&rdfreq=500&rwfreq=500&rlead=250&sufs=0&order=r&is_summary_on=1&ResultCount=10&query=histfit&submitButtonName=Search]]
**RGB値を指定したプロット [#r4265bd9]
-&ref(colorplot_1.m);
#ref(colorplot_1.png);
-&ref(colorplot_2.m);
#ref(colorplot_2.png);