Showing posts with label Matlab. Show all posts
Showing posts with label Matlab. Show all posts

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中

Wednesday, 7 March 2012

两组数据,不同颜色,现实在plot图中

x1 = data(1:21,2);
t1 = data(1:21,4);

x2 = data(22:40,2);
t2 = data(22:40,4);

plot(x1,t1,'.b',x2,t2,'.r');

%x轴 y轴
xlabel('# Words');
ylabel('# Topics');

添加图标
legend('arm','topic-arm'); %分别将字符串1、字符串2标注到图中,每个字符串对应的图标为画图时的图标。

Tuesday, 6 March 2012

boxplot

%导入数据,默认存入data矩阵

a1 = data(1:21,4); %第四列的第1行到第21行存入到列向量a1中
a2 = data(22:40,4); %第四列的第22行到第40行存入到列向量a2中
a2 = [a2' [NaN,NaN]]' %因为a2比a1少两个,所以用NaN填充
A = [a1,a2]; %构造矩阵
boxplot(A,'labels',{'ARM','ARM-TOPIC'}); %画图 boxplot

boxplot图画出最小值,1/4位置值,median, 3/4位置值和最大值

Tuesday, 31 January 2012

Matlab draw plot graph closed automatically

Matlab 7.4
Mac 10.6

Problem:
When I use Matlab to draw graphs, like hist(x,y), scatter(x,x), the matlab will close automatically

Solution:
http://www.mathworks.com/matlabcentral/answers/11086-matlab-closing-automatically-when-plotting-data-or-opening-an-existing-saved-figure


There is an incompatibility in a recent Java update (1.6.0_26) affecting MATLAB versions R2007a, R2007b and R2008a, that can be worked around by following these steps:
1. Close MATLAB, if it is running.
2. In Terminal or xterm , type:
open -a TextEdit /Applications/MATLAB_R2008a/bin/.matlab7rc.sh
In the path above, change "/Applications/MATLAB_R2008a/bin/" accordingly depending on your version of MATLAB's root folder name.
3. In the editor, navigate to Line 410 to locate:
DYLD_LIBRARY_PATH=
This line is a part of the following code in the "mac" section of matlab7rc.sh:
if [ "$DYLD_LIBRARY_PATH" != "" ]; then
   DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
else
   DYLD_LIBRARY_PATH=
fi
4. Change the line from
DYLD_LIBRARY_PATH
to
DYLD_LIBRARY_PATH=/System/Library/Frameworks/JavaVM.framework/Libraries
For users on MATLAB R2007a and R2007b, after making the change in the "mac" section, make the same change the "maci" section (right below the "mac" section).
5. Save the changes (Command-S).
6. Restart MATLAB.