Matlab大数值计算题目

Matlab大数值计算题目
Matlab大数值计算题目

Matlab大数值计算题目

1、统计附件1中的数据,对其中的数据划分区间,从0到50,每

10个单位一个区间,分为5个区间,统计每个区间的数量,画出柱状图。

Matlab程序:

clear;clc;close all

Data=xlsread('数据.xls');

Q=0:10:50;

n=length(Data);

m=length(Q);

T=zeros(size(Q));

for s=1:n

for t=1:m-1

if Data(s)>Q(t)&Data(s)

T(t)=T(t)+1;

end

end

end

T(end)=[];

bar(T)

xlabel('区间划分','fontsize',13)

ylabel('每个区间数据个数','fontsize',13)

2、统计附件2中第二列数据中1至100每个数字出现的总次数,

附件2中第三列为每出现第二列数字所对应的次数,最后画出柱状图。

Matlab程序:

clear;clc;close all

Data=load('WEIBOIDWITHCOMMENTS.txt');

DATA=Data(:,2);

t=Data(:,3);

% m=max(DATA);

m=100;

T=zeros(m,1);

for i=1:m

data=DATA;

data(data~=ones(size(data))*i)=0;

data(data~=0)=1;

n=data.*t;

N=sum(n);

T(i)=N;

end

bar(T)

3、 找到矩阵迷宫的通路,矩阵第1行第1列为迷宫的入口,第8行

第8列为迷宫的出口。(0表示路,1表示墙)

000

00000011

11010000

01010010

11010010

11010010

00011010

01000011

11110??????????????????????????

Matlab 程序:

主程序:

clear all

clc

maze=[0,0,0,0,0,0,0,0;

0,1,1,1,1,0,1,0;

0,0,0,0,1,0,1,0;

0,1,0,0,0,0,1,0;

0,1,0,1,1,0,1,0;

0,1,0,0,0,0,1,1;

0,1,0,0,1,0,0,0;

0,1,1,1,1,1,1,0];

total=0;

maze(1,1)=3;

[total,maze]=search(1,1,maze,total);

子程序:

function [total,maze]=search(i,j,maze,total) fx(1:4)=[0,1,-1,0];

fy(1:4)=[1,0,0,-1];

for k=1:4

newi=i+fx(k);

newj=j+fy(k);

if

(newi<=8)&(newj<=8)&(newi>=1)&(newj>=1)&(maze(new i,newj)==0)

maze(newi,newj)=3;

if newi==8&newj==8

total=total+1;

maze

else

[total,maze]=search(newi,newj,maze,total);

end

end

end

maze(i,j)=2;

相关主题
相关文档
最新文档