Wednesday, 11 June 2014

画Beta分布图
X=0:0.01:1;

y1 = betapdf(X, 40, 40 );
figure;
plot(X,y1,'Color','g');

hold on;
y2 = betapdf(X,100,100);
plot(X,y2,'Color','r');

hold on;
y3 = betapdf(X,20,40);
plot(X,y3,'Color','b');

Friday, 6 June 2014

intersect 例子

INTERSECT(A,B) for vectors A and B, returns the values common to the two vectors. MATLAB sorts the results.  A and B can be cell arrays of strings.

For example, A=[1 2 3], B= [ 2 3 4]
The result of intersect(A,B) should be [2 3]

[dummy, indexA, indexB] = intersect(A,B)

dummy = [2 3]
indexA = [1 2]
indexB = [2 3]

Tuesday, 27 May 2014

CUMPROD (Cumulative product of elements) 例子

Example:

if X=[0 1 2;3 4 5]
then cumprod(X,1) is
[0 1 2; 0 4 10]
沿着列的方向累积连乘 (对第一个长度不为1的维度进行计算)
所以第一行,保持不变,第二行的元素变成他本身与对应的第一行元素的乘积
cumprod(X,2) 沿着行方向
所以结果为[0 0 0;3 12 60]


Monday, 25 February 2013

matlab size 函数用法

用于返回一个矩阵的行数和列数

假设有一个4*5矩阵 A

s = size(A) %矩阵的行数和列数保存在s中  s= [4,5]
[h,l] = size(A)  %h=4, l=5
h = size(A,1) %行数h=4
l = size(A,2) %列数l=5

Friday, 11 May 2012

zeros and ones 
ones to generate an array in which the value of elements are 1;
zeros to generate an array in which the value of elements are 0;

ones(2,4) two rows * four columns all one
1 1 1 1
1 1 1 1

ones(3) 
1 1 1
1 1 1
1 1 1

访问矩阵
假设 A=
1 2 3
2 2 2
4 4 4
访问A的第一行,第二列
A(1,2) = 2

Thursday, 22 March 2012

ttest2


合并两个数组

b1 = data(1:10,4); %b1来自第四列的第一到第十个元素
b2 = data(11:20,4); %b2来自第四列的第十一到第二十个元素

b12 = [b1;b2]; %合并b1,b2到b12中