您的位置:首页 > 编程语言 > MATLAB

Simple Matlab/Octave Commands to Process Data

2012-12-07 03:32 190 查看
To load data in following format stored in a text file "read_pos' into Matlab/Octave, use commands<br />

f=fopen('read_pos','r'); % open file
a=textscan(f,'%s%d');  % read file
y=a{2}; % a is a cell: a{1} stores read id, a{2} stores numbers.


Then data of the second column are stored in variable y.

r12353.1 	2407054.5
r12361.1 	5328858.5
r12363.1 	2360272
r12368.1 	4726440.5
r12372.1 	2224001
r12373.1 	5165613.5
r12381.1 	501776
r12385.1 	3475398
r12394.1 	3376364
r12401.1 	2142875.5
r12411.1 	2191090.5
r12419.1 	1240590
r12420.1 	4903572
r12422.1 	767011.5
r12426.1 	3575915.5
r12429.1 	554956
r12433.1 	4786335
r12435.1 	3373955.5
r12442.1 	5363611.5
r12452.1 	1903660.5
r12454.1 	2784165
r12466.1 	5137479
r12470.1 	592191


If there are only numbers stored in file "read_pos", following commands should be used:

f=fopen('read_pos','r'); % open file
a=textscan(f,'%s%d');  % read file
y=cell2mat{a}; % convert cell a to vector
size(y) % check the size
To plot the distribution of all the numbers, you can:
x=zeros(size(y));
plot(y,x,'bo');
If another data set z is also loaded and you want to plot y and z in the same graph, you can:

figure
x=zeros(size(y)); plot(y,x,'bo');
hold on
x=ones(size(z));
plot(z,x,'r+');
To annotate and scale the graph, use commands;

xlabel('AMD Data k-mer Occurrances');
title('GPD Classification of AMD k-mers')
legend('Bin 1','Bin 2')
axis([-5 5 0 10000]) % scale axes


A matlab function to plot multiple datasets:

function result=plot_distr(varargin)

nVarargs=length(varargin);

marker={'bo' 'r+' 'k*' 'gs' 'y^' 'md' 'cp' 'bx' 'r.' 'k>' 'gh' 'y<'};
figure
for k=1:nVarargs
f=fopen(varargin{k},'r');
a=textscan(f,'%d');
y=cell2mat(a);
x=zeros(size(y))+k;
plot(y,x,marker{k});
hold on
end
ylim([0-5*nVarargs 6*nVarargs]); % scale y-axis


To use it, call
plot_distr('file1','file2',...,'filen').
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐