当前位置:文档之家› 2015-4matlab程序设计大作业评分标准

2015-4matlab程序设计大作业评分标准

命题人: 龙佳乐 审核人: 试卷分类(A 卷或B 卷) A 五邑大学 试 卷 学期: 2014 至 2015 学年度 第 2 学期课程: Matlab 程序设计 课程代号: 0702210使用班级:140707,140708 姓名: 学号: 题一设A 是一个256×256的矩阵,编写一个函数,格式为 B=function_name(A, n),其中 n 为一个正整数(≤256×256),该函数只保留A 矩阵中绝对值最大的 n 个元素,其他元素值设为零,输出到B 矩阵。

测定n=500时程序运行时间。

题二将一个绘图界面分4幅,选择合适的步长在左上幅与右下幅绘制出下列函数的图形。

①,22x ππ⎡⎤∈-⎢⎥⎣⎦② 228x y +=。

(25分) 题三设计类似下图所示的图形用户界面系统,要求有绘图界面有按键可输入参数。

用户按不同的按纽输入不同的参数可产生不同的效果。

该图为示意图,界面系统的功能可以是画图可以是修改图形参数或者其他。

(40分)评分标准:三个题目均正确完成为良好,若第三题设计完整合理、布局美观则为优;只完成前两题,第三题初步完成为中,第三题未完成为及格;只完成前两题任一题,第三题正确完成为中;只完成一题,则不及格。

function [B]=function_mane(A,n)t=cputime;a=zeros(1,256*256);for p=1:1:length(a) a(p)= abs(A(p));end s_a=sort(a,'descend');n_a=s_a(n);B=max(A,n_a);for i=1:1:256 for j=1:1:256if B(i,j)==n_a B(i,j)=0;endendendtime=cputime-t;fprintf('Run time is %f.\n',time);2.函数:function B=E_max(A,n) B=zeros(256,256); R=reshape(A,1,256*256); R=sort(R,'descend'); for i=1:n [x,y]=find(A==R(i)); B(x,y)=R(i); end主程序:>> A=rand(256,256); >> tic; >> B=E_max(A,300); >> t=toc t = 21.3786L=length(A);b=A(1,:);for i=2:Lb=cat(2,b,A(i,:));end;[sortb,index]=sort(b);for i=1:(L^2-n)sortb(i)=0;end;for i=1:L^2sortbb(index(i))=sortb(i);endc=sortbb(1:L);for i=1:(L-1)c=cat(1,c,sortbb((i*L+1):(i*L+L)));endfuction B=function_name(A, n)C=zeros(245,245);A_abs=abs(A);minA=min(min(A_abs))for (ni=1:n)[max_ys yis]=max(A_abs);[max_x xi]=max(max_ys);yi=yis(xi);C(yi,xi)=A(yi,xi);C(yi,xi)=minA;endB=C;function [c]=function_q(x,n)t=cputime; %获取当前CPU时间a=zeros(1,256*256); %生成一个1行256×256列的零矩阵for p=1:1:length(a) %将矩阵x的值赋给a矩阵a(p)=x(p); %根据你说的意思,个人认为这里应该取绝对值,ends_a=sort(a,'descend'); %对矩阵a进行降序排序,最大的在前面n_a=s_a(n); %获取排序后第n大的值,即矩阵x中第n大的值%根据你后面的意思,个人认为这里应该取n+1; %即n_a = s_a(n+1);c=max(x,n_a); %将矩阵x中小于n_a的值赋值为n_a,最后传递给c矩阵%遍历c矩阵,将所有值为n_a的赋值为0for i=1:1:256for j=1:1:256if c(i,j)==n_a c(i,j)=0;endendendtime=cputime-t; %获取程序运行时间fprintf('Run time is %f.\n',time); %输出程序运行时间第二题subplot(2,2,1);>> ezplot('(cos(x))^(1/2)',[-pi./2,pi./2]);>> xlabel('自变量x')>> ylabel('因变量y');>> subplot(2,2,2);>> subplot(2,2,3);>> subplot(2,2,4)>> ezsurfc('x^2+y^2');>>title(…….)>> text(-13,-12,' x^2+y^2=8');text函数用于在图形中指定的位置上显示字符串。

用法text(x,y,'string')在图形中指定的位置(x,y)上显示字符串stringfuction B=function_name(A, n)C=zeros(256,256);A_abs=abs(A);minA=min(min(A_abs))[max_x xi]=max(max_ys);yi=yis(xi);C(yi,xi)=A(yi,xi);C(yi,xi)=minA;endB=C;曲线下面显示画出的改曲线的命令,右边是一系列的按钮,按钮可以画出>> mane(rand(256,256),100)>> clf;>> set(gcf,'Unit','normalized','Position',[0.2,0.3,0.55,0.30]);>> set(gcf,'Menubar','none','Name','图形用户界面系统展示','NumberTitle','off'); >> axes('Position',[0.05,0.15,0.55,0.71]);>> uicontrol(gcf,'style','text','Unit','normalized',...'Posi',[0.63,0.85,0.2,0.1],'String',...'请在下面对话框输入绘图命令','Horizontal','center')>> hedit=uicontrol(gcf,'Style','edit','Unit','normalized',...'Posi',[0.63,0.15,0.2,0.68],...'Max',2);>> hpopup=uicontrol(gcf,'Style','popup','Unit','normalized',...'Posi',[0.85,0.8,0.15,0.15],'String',...'Spring|Summer|Autumn|Winter','Call',...'comm(hedit,hpopup,hlist)');>> hlist=uicontrol(gcf,'String','list','Unit','normalized',...'Posi',[0.85,0.55,0.15,0.25],'String',...'Grid on|Grid off|Box on|Box off','Call',...'comm(hedit,hpopup,hlist)');>> clf;set(gcf,'Unit','normalized','Position',[0.2,0.3,0.55,0.30]);set(gcf,'Menubar','none','Name','图形用户界面系统展示','NumberTitle','off'); axes('Position',[0.05,0.15,0.55,0.71]);uicontrol(gcf,'style','text','Unit','normalized',...'Posi',[0.63,0.85,0.2,0.1],'String',...'请在下面对话框中输入绘图命令','Horizontal','center')hedit=uicontrol(gcf,'Style','edit','Unit','normalized',...'Posi',[0.63,0.15,0.2,0.68],...'Max',2);hpopup=uicontrol(gcf,'Style','popup','Unit','normalized',...'Posi',[0.85,0.8,0.15,0.15],'String',...'Spring|Summer|Autumn|Winter','Call',...'comm(hedit,hpopup,hlist)');hlist=uicontrol(gcf,'String','list','Unit','normalized',...'Posi',[0.85,0.55,0.15,0.25],'String',...'Grid on|Grid off|Box on|Box off','Call',...'comm(hedit,hpopup,hlist)');>> hpust1=uicontrol(gcf,'String','pust','Unit','normalized',...'Posi',[0.85,0.35,0.15,0.15],'String',...'绘图','Call','comm(hedit,hpopup,hlist)');>> uicontrol(gcf,'String','pust','Unit','normalized',...'Posi',[0.85,0.15,0.15,0.15],'String',...'关闭','Call','close all');图形程序[x,y,z]=sphere(20);subplot(1,2,1);surf(x,y,z);axis equal;light('Post',[0,1,1]);shading interp;hold on;polt(0,1,1,'p');light('Posi',[1,0,1]);shading interp;hold on;plot3(1,01,1,'p');text(1,0,1,'light');x0=str2num(get(handles.edit1,'string'));%´Ó¾²Ì¬Îı¾¿òÄÚ¶ÁÈëÊäÈë²ÎÊýxd=str2num(get(handles.edit2,'string'));%´Ó¾²Ì¬Îı¾¿òÄÚ¶ÁÈëÊäÈë²ÎÊýxe=str2num(get(handles.edit3,'string'))%´Ó¾²Ì¬Îı¾¿òÄÚ¶ÁÈëÊäÈë²ÎÊýx=[x0:xd:xe];hlines=plot(x,sin(x)); %»æÖƲ¢·µ»Ø¾ä±úhandles.line=hlines;guidata(hObject,handles); %¸üб£´æ¾ä±ú% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)close(gcf);%关闭窗口。

相关主题