![基于MATLAB的图像处理算法综合应用算法开发_第1页](http://file4.renrendoc.com/view/0bcf0445bd70f653268d101970f3ac31/0bcf0445bd70f653268d101970f3ac311.gif)
![基于MATLAB的图像处理算法综合应用算法开发_第2页](http://file4.renrendoc.com/view/0bcf0445bd70f653268d101970f3ac31/0bcf0445bd70f653268d101970f3ac312.gif)
![基于MATLAB的图像处理算法综合应用算法开发_第3页](http://file4.renrendoc.com/view/0bcf0445bd70f653268d101970f3ac31/0bcf0445bd70f653268d101970f3ac313.gif)
![基于MATLAB的图像处理算法综合应用算法开发_第4页](http://file4.renrendoc.com/view/0bcf0445bd70f653268d101970f3ac31/0bcf0445bd70f653268d101970f3ac314.gif)
![基于MATLAB的图像处理算法综合应用算法开发_第5页](http://file4.renrendoc.com/view/0bcf0445bd70f653268d101970f3ac31/0bcf0445bd70f653268d101970f3ac315.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 基于MATLAB的图像处理算法综合应用算法开发(一)实验类型: 研究(二)实验目的:1、培养应用MATLAB开发图像处理算法的能力。2、掌握开发综合性图像算法的技能与方法。(三)实验内容:弹孔中心位置的图像处理方法。(四)实验要求:开发出算法及程序代码,并获得处理结果。其基本原理是,先对图像进行边缘检测,后应用数学形态学的方法将边缘连接在一起,后填充,应用数学形态学方法对分割弹孔圆形化,再进行边缘检测获得弹孔边缘,最后应用最小二乘法拟合圆心的方法,获得弹孔中心。实验过程:打开MATLAB软件,在OPEN中选择我们在软件中设计好的算法程序。clear;close all;I0=imread(p
2、ic.jpg);%I0=rgb2gray(I3);x,y,z=size(I0);%I6=im2bw(I3,0.4);I4=edge(I0,canny,0.1);BW=strel(disk,1);BW2=strel(disk,1);I5=imdilate(I4,BW);I6=imfill(I5,holes);I7=imdilate(I6,BW2);BW3=strel(disk,3);I8=imerode(I7,BW3);I81=imfill(I8,holes);BW4=strel(disk,7);I9=imerode(I81,BW4);BW5=strel(disk,7);I10=imopen(I
3、9,BW5);figure(1),imshow(I0);figure(2),imshow(I4);figure(3),imshow(I5);figure(4),imshow(I6);figure(5),imshow(I7);figure(6),imshow(I8);figure(7),imshow(I9);figure(8),imshow(I10);hold on;boundaries = bwboundaries(I5);mun1,mun2=size(boundaries);for k=1:mun1 b = boundariesk; plot(b(:,2),b(:,1),g,LineWidt
4、h,3); hold on; bt1=b(:,1); bt2=b(:,2); cir_x,cir_y,radis=circlefitting(bt1,bt2); plot(cir_y,cir_x,r*,LineWidth,3); end然后选择run。软件则会根据我们编辑好的算法对目标图片进行弹孔轮廓提取,显示出计算好的图片如下: 基于MATLAB的图像处理算法综合应用算法开发(一)实验类型: 研究(二)实验目的:1、培养应用MATLAB开发图像处理算法的能力。2、掌握开发综合性图像算法的技能与方法。(三)实验内容:色彩目标提取图像处理应用实例。(四)实验要求:开发出算法及程序代码,并获得处理
5、结果。应用理论:色彩变换色彩变换原理,减色合成法:人眼看到物体的颜色是由于物体反射了物体颜色相同的光。光白光(三原色的混合体)照到物体上时,物体只把它自己的颜色对应的光线反射出来,其它的色光被吸收,即从白光中“减”去物体没有的颜色。这种情况叫减色合成。品红会吸收绿色,反射红色光和蓝色光。黄色会吸收白光中的蓝色,反射红色光和绿色光。青色会吸收白光中的红色,反射绿色和蓝色。(色度在附近时为红色,附近为绿色,附近为兰色)将原图c3.jpg进行如下编辑程序进行运算我们可得到色彩变换结果程序如下:clear;%清除工作区内所有的变量close all;%关闭所有的figure%global i j y
6、c1 c2 sat hue;Iinp=imread(fig89.bmp);ysize,xsize,zsize=size(Iinp);m_inty=0.5;m_hue=200;m_sat=1;for j=1:ysize for i=1:xsize image_r(j,i)=Iinp(j,i,1); image_g(j,i)=Iinp(j,i,2); image_b(j,i)=Iinp(j,i,3); y(j,i)=double(0.0); c1(j,i)=double(0.0); c2(j,i)=double(0.0); sat(j,i)=double(0.0); hue(j,i)=double
7、(0.0); endend%由RGB变成色差信号y,c1,c2=Rgb_to_yc(image_r,image_g,image_b,xsize,ysize);%由色差信号计算饱和度和色相sat,hue=C_to_SH(c1,c2,xsize,ysize);%亮度饱合度色调的调整out_y,out_sat,out_hue=Change_YSH(y,sat,hue,m_inty,m_sat,m_hue,xsize,ysize);%由色调和饱合度计算色差信号m_c1,m_c2=SH_to_C(out_sat,out_hue,xsize,ysize);%由亮度色差变换RGB信号out_r,out_g,
8、out_b=Yc_to_rgb(out_y,m_c1,m_c2,xsize,ysize);for j=1:ysize for i=1:xsize Iout(j,i,1)=out_r(j,i); Iout(j,i,2)=out_g(j,i); Iout(j,i,3)=out_b(j,i); endendfigure(1),imshow(Iinp);figure(2),imshow(image_r);figure(3),imshow(image_g);figure(4),imshow(image_b);figure(5),imshow(Iout);运行程序后得到如下图片: 实验结果分析:基于YUV
9、彩色系统的灰度图像着色方法用彩色参考图着色假定相邻的像素之间如果有相似的Y 值,那么就会有相似的U 和V 值;视觉上对U 、V 变化的不敏感性,同时假定同类色中颜色的区别主要是Y 值作用的结果。基本原则:1)彩色图像中U、V 值显著改变的临界线, 也是Y 值显著改变的临界线;2)同类色中相近颜色的区别在视觉上主要是Y 值作用的结果实例2、彩色目标提取,(原理与色彩变换相同,应用图像像素的点的色度进行判别,色度在附近时为红色,附近为兰色,附近为绿色)我们根据变换远离编辑出如下程序:clear;%清除工作区内所有的变量close all;%关闭所有的figure%global i j y c1 c
10、2 sat hue;xsize=640;ysize=480;m_inty=1;m_hue=0;m_sat=2;y(1:xsize,1:ysize)=double(0.0);c1(1:xsize,1:ysize)=double(0.0);c2(1:xsize,1:ysize)=double(0.0);sat(1:xsize,1:ysize)=double(0.0);hue(1:xsize,1:ysize)=double(0.0);%path1= sprintf(red%d.bmp,k);Iinp=imread(c3.jpg);image_r(:,:)=Iinp(:,:,3);image_g(:,
11、:)=Iinp(:,:,2);image_b(:,:)=Iinp(:,:,1);%由RGB变成色差信号y,c1,c2=Rgb_to_yc(image_r,image_g,image_b,xsize,ysize);%由色差信号计算饱和度和色相sat,hue=C_to_SH(c1,c2,xsize,ysize);%亮度饱合度色调的调整%ss=max(sat(:);%x=0:1:360;%figure(10),hist(hue,x);%figure(11),histfit(hue,x)hi,hj,hall = find(hue20&hue20&hue20&hue 1-binocdf(100,162,
12、0.5)ans = 0.0010433相关函数 HYPERLINK jar:file:/C:/Program%20Files/MATLAB/R2010a/help/toolbox/stats/help.jar%21/binofit.html binofit | HYPERLINK jar:file:/C:/Program%20Files/MATLAB/R2010a/help/toolbox/stats/help.jar%21/binoinv.html binoinv | HYPERLINK jar:file:/C:/Program%20Files/MATLAB/R2010a/help/tool
13、box/stats/help.jar%21/binopdf.html binopdf | HYPERLINK jar:file:/C:/Program%20Files/MATLAB/R2010a/help/toolbox/stats/help.jar%21/binornd.html binornd | HYPERLINK jar:file:/C:/Program%20Files/MATLAB/R2010a/help/toolbox/stats/help.jar%21/binostat.html binostat | HYPERLINK jar:file:/C:/Program%20Files/
14、MATLAB/R2010a/help/toolbox/stats/help.jar%21/cdf.html cdf附:二项式分布(binomial distribution )定义二项分布的概率密度函数为where k is the number of successes in n trials of a Bernoulli process with probability of success p.The binomial distribution is discrete, defined for integers k = 0, 1, 2, . n, where it is nonzero.
15、背景The binomial distribution models the total number of successes in repeated trials from an infinite population under the following conditions:Only two outcomes are possible on each of ntrials.The probability of success for each trial is constant.All trials are independent of each other.The binomial
16、 distribution is a generalization of the HYPERLINK jar:file:/C:/Program%20Files/MATLAB/R2010a/help/toolbox/stats/help.jar%21/brn2ivz-2.html Bernoulli distribution; it generalizes to the HYPERLINK jar:file:/C:/Program%20Files/MATLAB/R2010a/help/toolbox/stats/help.jar%21/brn2ivz-84.html multinomial di
17、stribution.参数Suppose you are collecting data from a widget manufacturing process, and you record the number of widgets within specification in each batch of100. You might be interested in the probability that an individual widget is within specification. Parameter estimation is the process of determ
18、ining the parameter, p, of the binomial distribution that fits this data best in some sense.One popular criterion of goodness is to maximize the likelihood function. The likelihood has the same form as the binomial pdf above. But for the pdf, the parameters (nandp) are known constants and the variab
19、le isx. The likelihood function reverses the roles of the variables. Here, the sample values (the xs) are already observed. So they are the fixed constants. The variables are the unknown parameters. MLE involves calculating the value of p that give the highest likelihood given the particular set of
20、data.The function HYPERLINK jar:file:/C:/Program%20Files/MATLAB/R2010a/help/toolbox/stats/help.jar%21/binofit.html binofit returns the MLEs and confidence intervals for the parameters of the binomial distribution. Here is an example using random numbers from the binomial distribution with n=100 and
21、p=0.9. r = binornd(100,0.9)r = 85 phat, pci = binofit(r,100)phat = 0.85pci = 0.76469 0.91355The MLE for parameterp is0.8800, compared to the true value of0.9. The 95% confidence interval forp goes from 0.7998 to0.9364, which includes the true value. In this made-up example you know the true value of
22、p. In experimentation you do not.示例The following commands generate a plot of the binomial pdf for n = 10 and p = 1/2.x = 0:10;y = binopdf(x,10,0.5);plot(x,y,+) 相关内容 HYPERLINK jar:file:/C:/Program%20Files/MATLAB/R2010a/help/toolbox/stats/help.jar%21/bqt29ct.html l bqt290a-1 Discrete Distributions附:二项
23、式分布(网上)定义若某事件概率为p,现重复试验n次,该事件发生k次的概率为:P=C(k,n)pk(1-p)(n-k)C(k,n)表示组合数,即从n个事物中拿出k个的方法数。二项分布的概念考虑只有两种可能结果的随机试验,当成功的概率()是恒定的,且各次试验相互独立,这种试验在统计学上称为贝努里试验(Bernoullitrial)。如果进行n次贝努里试验,取得成功次数为X(X=0,1,n)的概率可用下面的二项分布概率公式来描述:P=C(X,n) X(1-)(n-X)式中的n为独立的贝努里试验次数,为成功的概率,(1-)为失败的 HYPERLINK /doc/5399415.html t _blan
24、k 概率,X为在n次贝努里试验中出现成功的次数,C(X,n)表示在n次试验中出现X的各种组合情况,在此称为二项系数(binomialcoefficient)。内容简介二项分布,伯努里分布:进行一系列试验,如果1. 在每次试验中只有两种可能的结果,而且是互相对立的;2. 每次实验是独立的,与其它各次试验结果无关;3. 结果事件发生的 HYPERLINK /doc/5399415.html t _blank 概率在整个系列试验中保持不变,则这一系列试验称为伯努力试验。在这试验中,事件发生的次数为一 HYPERLINK /doc/2273201.html t _blank 随机事件,它服从二次分布。
25、二项分布可以用于可靠性试验。可靠性试验常常是投入n个相同的式样进行试验T小时,而只允许k个式样失败,应用二项分布可以得到通过试验的概率。一个事件必然出现,就说它100%要出现。100%=1,所以100%出现的含义就是出现的概率P=1。即必然事件的出现概率为1。若掷一枚硬币,正面向上的结果的概率为0.5。反面向上的结果的概率也是0.5。则出现正面向上事件或者反面向上事件的概率就是0.5+0.5=1,即二者必居其一。若掷两次硬币,由独立事件的概率乘法定理那么两次都是正面(反面)向上的概率是0.50.5=0.25。另外第一个是正第二个是反的出现概率也是0.50.5=0.25。同理第一个反第二个正的出
26、现概率也是0.50.5=0.25。于是一正一反的概率是前面两个情况的和,即0.25+0.25=20.25=0.5。它们的合计值仍然是1。binopdf二项分布的概率密度函数语法格式Y = binopdf(X,N,P)函数功能Y = binopdf(X,N,P) 计算X中每个X(i)的概率密度函数,其中,N中对应的N(i)为试验数,P中对应的P(i)为每次试验成功的概率。Y, N, 和 P 的大小类型相同,可以是向量、矩阵或多维数组。输入的标量将扩展成一个数组,使其大小类型与其它输入相一致。N中的值必须是正整数,0 P 1 。对于给出的x和两个参数n和p,二项分布概率密度函数为其中 q = 1
27、p。 y为n次独立试验中成功x次的概率,其中,每次试验成功的概率为p。指示器函数 I(0,1,.,n)(x) 确保x 取值为 0, 1, ., n。 示例一个质量检查技术员一天能测试200块电路板。假设有 2% 的电路板有缺陷,该技术员在一天的测试中没有发现有缺陷的电路板的概率是多少?binopdf(0,200,0.02)ans =0.0176质量检查技术员一天中最大可能检测出有缺陷的电路板是多少块?defects=0:200;y = binopdf(defects,200,.02);x,i=max(y);defects(i) ans =4相关函数 HYPERLINK jar:file:/D:
28、/Program%20Files/MATLAB/help/toolbox/stats/help.jar%21/binocdf.html binocdf | HYPERLINK jar:file:/D:/Program%20Files/MATLAB/help/toolbox/stats/help.jar%21/binofit.html binofit | HYPERLINK jar:file:/D:/Program%20Files/MATLAB/help/toolbox/stats/help.jar%21/binoinv.html binoinv | HYPERLINK jar:file:/D:
29、/Program%20Files/MATLAB/help/toolbox/stats/help.jar%21/binornd.html binornd | HYPERLINK jar:file:/D:/Program%20Files/MATLAB/help/toolbox/stats/help.jar%21/binostat.html binostat | HYPERLINK jar:file:/D:/Program%20Files/MATLAB/help/toolbox/stats/help.jar%21/pdf.html pdfdlmread将以ASCII码分隔的数值数据文件读入到矩阵中语
30、法格式M = dlmread(filename)M = dlmread(filename, delimiter)M = dlmread(filename, delimiter, R, C)M = dlmread(filename, delimiter, range)函数功能M = dlmread(filename)读取有分隔符的ASCII数值数据文件filename,并把数据给到矩阵M中。文件名(filename)以字符串形式用单引号括起来。 dlmread 从文件的格式中推断分隔符。M = dlmread(filename, delimiter)指定分隔符delimiter。使用 t 代表制
31、表符 tab 作为分隔。M = dlmread(filename, delimiter, R, C)R和C指定了数据读取数据,其左上角的值位于文件中的第R行,第C列。R和C从0开始,所以R=0, C=0 指向文件中的第一个值。M = dlmread(filename, delimiter, range)读取由range = R1 C1 R2 C2指定的区域块, (R1,C1)是左上角,(R2,C2)是右下角。也可以使用电子表格表示法来指定,如range = A1.B7。备注All data in the input file must be numeric. dlmread does not
32、read files that contain nonnumeric data, even if the specified rows and columns contain only numeric data.若没有指定分隔符,当从文件格式中推断分隔符时,连续的空格符当作一个分隔符对待。若指定了分隔符,则重复的分隔符将分别作为单独的分隔符对待。If you want to specify an R, C, or range input, but not a delimiter, set the delimiter argument to the empty string, (two cons
33、ecutive single quotes with no spaces in between, ). For example,M = dlmread(myfile.dat, , 5, 2)In this case, dlmread treats repeated white spaces as a single delimiter.Dlmread将用0填充没有边界的区域。有多行的数据文件,若以非空格分隔符结束,例如分号,则导入后会多产生全0的一列在最后。Dlmread在导入任何复数时,将其作为一个整体导入到一个复数单元中。下面是有效的复数格式:i|jExample: 5.7-3.1ii|jE
34、xample: -7j嵌入了空格的复数是不正确的格式,空格将被认为是分隔符。示例例1Export a 5-by-8 test matrix M to a file, and read it with dlmread, first with no arguments other than the filename:M = gallery(integerdata, 100, 5 8, 0); dlmwrite(myfile.txt, M, delimiter, t)dlmread(myfile.txt)ans = 96 77 62 41 6 21 2 42 24 46 80 94 36 20 75
35、 85 61 2 93 92 82 61 45 53 49 83 74 42 1 28 94 21 90 45 18 90 14 20 47 68Now read a portion of the matrix by specifying the row and column of the upper left corner:dlmread(myfile.txt, t, 2, 3)ans = 92 82 61 45 53 42 1 28 94 21 90 14 20 47 68This time, read a different part of the matrix using a rang
36、e specifier:dlmread(myfile.txt, t, C1.G4)ans = 62 41 6 21 2 80 94 36 20 75 93 92 82 61 45 74 42 1 28 94例2Export matrix M to a file, and then append an additional matrix to the file that is offset one row below the first:M = magic(3);dlmwrite(myfile.txt, M*5 M/5, )dlmwrite(myfile.txt, M/3, -append, .
37、 roffset, 1, delimiter, )type myfile.txt40 5 30 1.6 0.2 1.215 25 35 0.6 1 1.420 45 10 0.8 1.8 0.4 2.6667 0.33333 21 1.6667 2.33331.3333 3 0.66667When dlmread imports these two matrices from the file, it pads the smaller matrix with zeros:dlmread(myfile.txt) 40.0000 5.0000 30.0000 1.6000 0.2000 1.200
38、0 15.0000 25.0000 35.0000 0.6000 1.0000 1.4000 20.0000 45.0000 10.0000 0.8000 1.8000 0.4000 2.6667 0.3333 2.0000 0 0 0 1.0000 1.6667 2.3333 0 0 0 1.3333 3.0000 0.6667 0 0 0替代作为dlmread的替代,可使用导入向导。选择菜单 “File | Import Data” 激活导入向导。相关函数 HYPERLINK jar:file:/D:/Program%20Files/MATLAB/help/techdoc/help.jar
39、%21/ref/dlmwrite.html dlmwrite | HYPERLINK jar:file:/D:/Program%20Files/MATLAB/help/techdoc/help.jar%21/ref/textscan.html textscanfprintf写数据到文本文件或输出到命令窗口语法格式fprintf(fileID, format, A, .)fprintf(format, A, .)count = fprintf(.)函数功能fprintf(fileID, format, A, .) fileID为文件句柄,指定要写入的文件;format是用来控制所写数据格式的格式
40、符;A是用来存放数据的矩阵。applies the format to all elements of array A and any additional array arguments in column order, and writes the data to a text file. fprintf uses the encoding scheme specified in the call to HYPERLINK jar:file:/D:/Program%20Files/MATLAB/help/techdoc/help.jar%21/ref/fopen.html fopen.fp
41、rintf(format, A, .) 将A中的数据按格式format输出到命令窗口。count = fprintf(.) 返回fprintf写的字节数。输入参数fileID取值为下面中的一种:从文件打开时所得到的文件句柄,为一个整数值。1 为标准输出设备(屏幕)。2 for standard error.fileID缺省时,输出到屏幕,即1为默认值。format单引号括起来的是 “转换控制字符串 ”,指定输出的格式。由下面给出的各部分的组合而成:百分号后紧跟的格式字符,如%s 。输出区域的宽度,精度,和其它选项(附加格式说明符)。要原样输出的文本(普通字符)。转义字符,包括:单引号% 百分号
42、反斜线a响铃b退格符fForm feedn换行r回车t水平制表符v垂直制表符xN十六进制数, NN八进制数, N转换字符和可选的操作符按以下顺序排列(包括空格):下表列出可用的转换字符和限定类型字符。数据类型转换说 明Integer, signed%d 或 %i十进制整数%ld 或 %li64-bit base 10 values%hd 或 %hi16-bit base 10 valuesInteger, unsigned%u十进制整数%o八进制整数(octal)%x十六进制整数 (hexadecimal), 使用字母 af%X十六进制整数 (hexadecimal), 使用字母AF%lu%l
43、o%lx or %lX64-bit values, 十、八、十六进制整数%hu%ho%hx or %hX16-bit values, 十、八、十六进制整数Floating-point number%f定点表示法%e指数表示法,如 3.141593e+00%E同 %e,但用E,如 3.141593E+00%g%e 或 %f的紧凑格式,没有尾部的0%G%E 或 %f的紧凑格式,没有尾部的0%bx or %bX%bo%bu双精度的十六、八、十进制数值如:%bx prints pi as 400921fb54442d18%tx or %tX%to%tu单精度的十六、八、十进制数值如:%tx print
44、s pi as 40490fdbCharacters%c单个字符%s字符串附加格式说明符,包括:字段宽度Minimum number of characters to print. Can be a number, or an asterisk (*) to refer to an argument in the input list. For example, the input list (%12d, intmax) is equivalent to (%*d, 12, intmax).精度For %f, %e, or %E: Number of digits to the right o
45、f the decimal point.Example: %6.4f prints pi as 3.1416For %g or %G Number of significant digits.Example: %6.4g prints pi as 3.142Can be a number, or an asterisk (*) to refer to an argument in the input list. For example, the input list (%6.4f, pi) is equivalent to (%*.*f, 6, 4, pi).FlagsActionFlagEx
46、ampleLeft-justify.%-5.2fPrint sign character (+ or ).+%+5.2fInsert a space before the value. % 5.2fPad with zeros.0%05.2fModify selected numeric conversions:For %o, %x, or %X, print 0, 0 x, or 0X prefix.For %f, %e, or %E, print decimal point even when precision is 0.For %g or %G, do not remove trail
47、ing zeros or decimal point.#%#5.0fIdentifierOrder for processing inputs. Use the syntax n$, where n represents the position of the value in the input list.For example, %3$s %2$s %1$s %2$s prints inputs A, B, C as follows: C B A B.The following limitations apply to conversions:Numeric conversions pri
48、nt only the real component of complex numbers.If you apply an integer or string conversion to a numeric value that contains a fraction, MATLAB overrides the specified conversion, and uses %e.If you apply a string conversion (%s) to integer values, MATLAB converts values that correspond to valid char
49、acter codes to characters. For example, %s converts 65 66 67 to ABC.Different platforms display exponential notation (such as %e) with a different number of digits in the exponent.环境示例Windows1.23e+004UNIX1.23e+04不同的操作系统环境显示的负零(-0) 不相同。转换字符环境%e 或 %E%f%g 或 %GWindows0.000000e+0000.0000000Others-0.00000
50、0e+00-0.000000-0A数值或字符数组。示例例1 输出多个数值和文本到屏幕。 B = 8.8 7.7 ; 8800 7700; fprintf(X is %4.2f meters or %8.3f mmn, 9.9, 9900, B)X is 9.90 meters or 9900.000 mmX is 8.80 meters or 8800.000 mmX is 7.70 meters or 7700.000 mm注:对B是按列处理。例2 对双精度数四舍五入取整,并输出到屏幕。 a = 1.02 3.04 5.06; fprintf(%dn, round(a);135例3 写一组数
51、据到文本文件中。x = 0:.1:1;y = x; exp(x); % 打开文件exp.txt为可写fid = fopen(exp.txt, w);fprintf(fid, %6.2f %12.8fn, y);fclose(fid); % 查看文件内容type exp.txtMATLAB导入功能,所有UNIX应用程序,和微软Word和写字板都把 n 作为一个换行符指示器。然而,如果你要用微软记事本读取文件,请使用“ r n”移动到新行再写。将之前的调用改写如下:fprintf(fid, %6.2f %12.8frn, y);输出结果不变。例4 在Windows系统上,将PC形式的指数表示法(三
52、位数的指数)转换到unix形式的表示法(两位数字),并打印数据到一个文件:a = 0.06 0.1 5 300 % 用sprintf转换数值数据到文本,使用%ea_str = sprintf(%et,a) % use strrep to replace exponent prefix with shorter versiona_str = strrep(a_str,e+0,e+);a_str = strrep(a_str,e-0,e-); %调用fprintf打印更新的文本字符串fid = fopen(newfile.txt,w);fprintf(fid, %s, a_str);fclose(
53、fid); % 查看文件内容type newfile.txt例5 在屏幕上显示一个超链接。例6 创建一个字符矩阵并存入磁盘,再读出赋值给另一个矩阵。 a=string; fid=fopen(d:char1.txt,w); fprintf(fid,%s,a); fclose(fid); fid1=fopen(d:char1.txt,rt); b=fscanf(fid1,%s)b =string例7 用fprintf输出一个数值矩阵。i = 1:10;square_root = sqrt(i);square = i.2;cube = i.3;% 拼接成一个大矩阵,行向量转置成列向量out = i square_root square cube ;% 输出数据for i = 1:10fprintf ( %2d %11.4f %6d %8dn,out(i,:);end%第1列整数输出,占2格%第2列实数输出,占11格,4位小数i = 1:10;square_root = sqrt(i);square = i.2;cube = i.3;% 拼接成一个大矩阵out = i; square_root; square; cube;% 输出数据fprintf ( %2d %11.4f %6d %8dn,out);%将第1列输出为第1行,格式对应;%将
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 小动物流行病知识竞赛考试题库300题(含答案)
- 2025年新型电力系统(配电自动化)职业技能竞赛参考试题库(含答案)
- 2025年安徽省职教高考《语文》核心考点必刷必练试题库(含答案)
- 2025年桂林山水职业学院高职单招职业技能测试近5年常考版参考题库含答案解析
- 2025年昆明幼儿师范高等专科学校高职单招职业技能测试近5年常考版参考题库含答案解析
- 2025年新疆建设职业技术学院高职单招语文2018-2024历年参考题库频考点含答案解析
- 中班冬季主题活动策划方案五篇
- 全新合同式环保管家服务下载
- 食品销售代理合同范本
- 商品房买卖合同预售
- 苏教版四年级数学下册第三单元第二课时《常见的数量关系》课件
- 浙江省台州市2021-2022学年高一上学期期末质量评估政治试题 含解析
- 中国高血压防治指南(2024年修订版)解读课件
- 2024年浙江省中考科学试卷
- 初三科目综合模拟卷
- 2024年全国高考新课标卷物理真题(含答案)
- 劳动合同薪酬与绩效约定书
- 足疗店营销策划方案
- 学校安全一岗双责
- 交通工程公司乳化沥青储油罐拆除工程安全协议书
- YS/T 441.1-2014有色金属平衡管理规范第1部分:铜选矿冶炼
评论
0/150
提交评论