Miyazawa’s Pukiwiki
MATLAB Note/グラフ
はすでに存在します。
開始行:
-目次
#contents
**2次元グラフ [#u9508999]
-以下の配列A(([[行列と魔方陣:http://shakosv.sk.tsukuba.ac...
>> 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/plo...
-プロット2
>> plot(A')
&ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/plo...
-プロット3
>> plot(A(1,:),A(2,:),'o')
&ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/plo...
-プロット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/plo...
***色を指定する [#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/plo...
**ヒストグラム [#g05d53d5]
-1次元データの分析
--関数HISTを使います。以下はヘルプから転載です。
--N = HIST(Y) は、10 個の等間隔のコンテナに Y の要素を分...
--例えば、
>> 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)+...
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)<=(i...
(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', 'FaceLighti...
xlabel('A'); ylabel('B'); zlabel('頻度 (回)'); title('頻...
axis tight; camlight left;
}}
---実行結果は以下のようになります。
#ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/his...
-正規分布を作る
#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 正規確率密度を重ね合わせたヒストグラム [[参...
**RGB値を指定したプロット [#r4265bd9]
-&ref(colorplot_1.m);
#ref(colorplot_1.png);
-&ref(colorplot_2.m);
#ref(colorplot_2.png);
終了行:
-目次
#contents
**2次元グラフ [#u9508999]
-以下の配列A(([[行列と魔方陣:http://shakosv.sk.tsukuba.ac...
>> 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/plo...
-プロット2
>> plot(A')
&ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/plo...
-プロット3
>> plot(A(1,:),A(2,:),'o')
&ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/plo...
-プロット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/plo...
***色を指定する [#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/plo...
**ヒストグラム [#g05d53d5]
-1次元データの分析
--関数HISTを使います。以下はヘルプから転載です。
--N = HIST(Y) は、10 個の等間隔のコンテナに Y の要素を分...
--例えば、
>> 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)+...
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)<=(i...
(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', 'FaceLighti...
xlabel('A'); ylabel('B'); zlabel('頻度 (回)'); title('頻...
axis tight; camlight left;
}}
---実行結果は以下のようになります。
#ref(http://shower.human.waseda.ac.jp/~m-kouki/matlab/his...
-正規分布を作る
#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 正規確率密度を重ね合わせたヒストグラム [[参...
**RGB値を指定したプロット [#r4265bd9]
-&ref(colorplot_1.m);
#ref(colorplot_1.png);
-&ref(colorplot_2.m);
#ref(colorplot_2.png);
ページ名:
既存のページ名で編集する