hist函数,给定一堆数据,统计数据在某一值的个数。plot是给定横/纵坐标向量,描绘点列。
统计频率---hist
第一步:用load导入文本数据,Matlab会自动生成以文件名命名的二维矩阵;
第二步:按列或按行取出所需要的数据,保存到变量;
第三步:添加标注文本。
保存为histogram.m %step1 load file filename = 'dragon.nf1500k_2.m.txt'; data = load(filename); %step2 retrieve relevant data freqOfGH = data(:,3); %step3 adjust the range of x,y range and draw histgram xRange=1:0.06:2.4;%for controlling the number of bars clf; set(gcf,'Color','w'); hist(freqOfGH, xRange); %step4 set annotating information axis([1,2.2,0,400]);% h = findobj(gca,'Type','patch'); set(h,'FaceColor',[1 0.76 0.05],'EdgeColor','w'); xlabel('Average times for running the GH algorithm', 'fontsize',12,'fontweight','b'); ylabel('Frequency', 'fontsize',12,'fontweight','b'); %title(filename); datacursormode on %show datatip,right click to add/delete the datatip
显示一堆数据,并且画出拟合线---plot, polyfit
第一步:用load导入文本数据,Matlab会自动生成以文件名命名的二维矩阵;
第二步:按列或按行取出所需要的数据,保存到变量;
第三步:将横/纵坐标调整到合理的范围,利用上述得到的数据,plot, polyfit画图;
第四步:添加标注文本。
保存为fittingCurve.m %step1 load filename = 'dragon.nf100k_2.m.txt'; data = load(filename);%load data from current folder %step2 retrieve relevant data enclosingVertices = data(:,2);%retrieve the second column of data refiningSteps = data(:,4);%retrieve the fourth column of data %step3 customize background and plot %customize color clr=[1 0.76 0.05]; clf; set(gcf,'Color','b');%set the color of figure background %set the style and color of marker plot(enclosingVertices,refiningSteps,'m+','MarkerEdgeColor',clr); hold on;%for plotting another figure on the same figure %restrict the range of x-value xAxis=0:max(enclosingVertices); %using polynormal(here we use linear) to fit the plotted data P=polyfit(enclosingVertices,refiningSteps,1); plot(xAxis,polyval(P,xAxis),'r-', 'LineWidth',2); %step4 set annotating information axis([200,3600,0,230]);%restrict the range of x- and y-axis xlabel('The number of swept verticefs','fontsize',12,'fontweight','b'); ylabel('The number of evolving steps','fontsize',12,'fontweight','b'); equation='y=0.05x+4.68'; text(2300,110,equation,'fontsize',11,'fontweight','b'); legend('Pair(m, steps)',equation); title('Sample Figure','fontsize',12,'fontweight','b'); hold off;
y扫描线上,画颜色各通道的Intensity值
第一步:导入数据,imread;
第二步:取得三个通道的值,并分别保存到三个独立的变量中r,g,b;
第三步:由于真彩色图像三个通道的颜色值在0-255范围内,而且是无符号整型。故需将它们转换到0-1的double型,作为各通道的强度值;
第四步:在同一个Figure上,沿着一条y扫描线,将该扫描线上各通道的值画出来。注意,plot的两个参数需要的是向量。
%step1 read image rgb=imread('Water lilies.jpg'); %step2 retrieve relevant data and show images r=rgb(:,:,1);%r chanel,range 0-255 subplot(2,2,1),imshow(r); title('R channel'); g=rgb(:,:,2);%g chanel,range 0-255 subplot(2,2,2),imshow(g); title('G channel'); b=rgb(:,:,3);%b chanel,range 0-255 subplot(2,2,3),imshow(b); title('B channel'); %step3 scale value of r,g,b channel to intensity(0-1) I1=double(r)./255;%intensity of channel r,range 0-1,double I2=double(g)./255;%intensity of channel g,range 0-1,double I3=double(b)./255;%intensity of channel b,range 0-1,double %step4 plot the intensity along the image's width- y-scan line [w,h,n]=size(rgb);%get the width and height of the image scanline=100;%customize the ?th y-scanline,it is within 0-w x=1:h;% x-axis for function plot I1_sl=I1(scanline,:);%y-axis for function plot I2_sl=I2(scanline,:);%y-axis for function plot I3_sl=I3(scanline,:);%y-axis for function plot subplot(2,2,4), plot(x,I1_sl,'-r',x,I2_sl,'-g',x,I3_sl,'-b'); %step5 add annotating information xlabel('y-coordinate[px]'); ylabel('signal intensity'); legend('R channel', 'G chnanel', 'B channel','Location','NorthWe