matlab实验5

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

MATLAB实验五

一、实验目的:

Be familiar with Input/Output functions

二、实验内容:

1. Write a m-file. The m-file creates an

array containing 150

⨯random values, sorts the array into ascending

order, opens a user-specified file for

writing only, then writes the array to

disk in 32-bit floating-point format ,

and close the file. It then opens the

file and read the data back into 510

⨯array.

a=randn(1,50);

b=sort(a);

fid=fopen('mydata','w');

count1=fwrite(fid,b,'float32');

statues=fclose(fid);

fid=fopen('mydata','r');

[c,count2]=fread(fid,[5,10],'float32');

statues=fclose(fid);

2. Edit a file as data4_4.txt that contains

44

⨯square matrix, then import the

array use uiimport function, and

calculate the inverse of the square

matrix .

inv(data4_4)

ans

-0.1649 0.0970 0.0037 0.1413

0.0713 -0.0369 0.1140 -0.1264

-0.0128 0.1985 -0.1077 0.0286

0.1077 -0.1488 0.0327 0.0182

3. Write a program to read a set of integers from an input data file, and locate the largest and smallest values within the data file. Print out the largest and smallest values, together with the lines on which they were found in one figure.

a=randn(1,200);

b=int8(a.*60);

fid=fopen('data','w');

count1=fwrite(fid,b,'float32');

statues=fclose(fid);

fid=fopen('data','r');

[c,count2]=fread(fid,[1,200],'float32');

statues=fclose(fid);

[x,maxn]=max(c);

[y,minn]=min(c);

num=1:1:200;

plot(num,c,maxn,x,'r*',minn,y,'g*')

1

1

相关文档
最新文档