博文
matlab实用程序百例1(2007-10-14 13:07:00)
摘要:1-32是:图形应用篇
33-66是:界面设计篇
67-84是:图形处理篇
85-100是:数值分析篇
实例1:三角函数曲线(1)
function shili01h0=figure('toolbar','none',... 'position',[198 56 350 300],... 'name','实例01');h1=axes('parent',h0,... 'visible','off');x=-pi:0.05:pi;y=sin(x);plot(x,y);xlabel('自变量X');ylabel('函数值Y');title('SIN( )函数曲线');grid on
实例2:三角函数曲线(2)
function shili02h0=figure('toolbar','none',... 'position',[200 150 450 350],... 'name','实例02');x=-pi:0.05:pi;y=sin(x)+cos(x);plot(x,y,'-*r','linewidth',1);grid onxlabel('自变量X');ylabel('函数值Y');title('三角函数');
实例3:图形的叠加
function shili03h0=figure('toolbar','none',... 'position',[200 150 450 350],... 'name','实例03');x=-pi:0.05:pi;y1=sin(x);y2=cos(x);plot(x,y1,... '-*r',... x,y2,... '--og');grid onxlabel('自变量X');ylabel('函数值Y');title('三角函数');
实例4:双y轴图形的绘制
function shili04h0=figure('toolbar','none',...&nb......
用matlab做的一个日历(2007-10-14 13:04:00)
摘要:function CalendarTable; % calendar 日历 % Example: % CalendarTable;
S=datestr(now); [y,m,d]=datevec(S); % d is day % m is month % y is year DD={'Sun','Mon','Tue','Wed','Thu','Fri','Sat'}; close all figure; for k=1:7; uicontrol(gcf,'style','text',... 'unit','normalized','position',[0.02+k*0.1,0.55,0.08,0.06],... 'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',... 'String',DD(k),'fontsize',16,'fontname','times new roman'); end h=1; ss='b'; qq=eomday(y,m); for k=1:qq; n=datenum(y,m,k); [da,w] = weekday(n); if k==d; ss='r'; end uicontrol(gcf,'style','push',... 'unit','normalized','position',[0.02+da*0.1,0.55-h*0.08,0.08,0.06],... 'BackgroundColor',0.6*[1,1,1],'ForegroundCol......
字符串排序(2007-10-14 13:02:00)
摘要:输入一组字符串,请你将它们按字典序输出。
此题由多组输入,每组输入的格式如下: n string1 string2 . . . stringn 其中0<=n<=100,任何一个字符串的长度不会超过100,字符串中只含有小写英文字母。当n=0时,程序即可结束。
#include "stdafx.h"#include <iostream>using namespace std;int main(){int n;char aa[101][101];char pp[101];cin>>n;while(n!=0){for(int i1=0;i1<n;i1++)cin>>aa[i1];
for(int i2=0;i2<n;i2++){if(strcmp(aa[i2], aa[i2+1]) >= 0){strcpy(pp,aa[i2]);strcpy(aa[i2],aa[i2+1]);strcpy(aa[i2+1],pp);}}cout<<n<<endl;for(int i3=0;i3<n;i3++)cout<<aa[i3]<<endl;cin>>n;}return 0;}
运行结果正确,但是也是超时!还没想到更好的办法提高效率!......
水仙花数(2007-10-14 12:59:00)
摘要:所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个“水仙花数”,因为153=13+53+33。本题要求打印出所有的水仙花数。#include "iostream.h"
int main()
{int i,n,j,k;
for(n=100;n<1000;n++)
{i=n/100;
j=n/10-i*10;
k=n%10;
if(n==i*i*i+j*j*j+k*k*k)
cout<<n<<" " ;
}
cout<<endl;
return 0;
}......
Sorting by Swapping(2007-10-14 12:58:00)
摘要:题目:Given a permutation of numbers from 1 to n, we can always get the sequence 1, 2, 3, ..., n by swapping pairs of numbers. For example, if the initial sequence is 2, 3, 5, 4, 1, we can sort them in the following way: 2 3 5 4 1 1 3 5 4 2 1 3 2 4 5 1 2 3 4 5 Here three swaps have been used. The problem is, given a specific permutation, how many swaps we needs to take at least. 我写的程序:
#include "stdafx.h"#include <iostream>using namespace std;int main(){int n,i=1,j,m,count,temp;int s[10001];cin>>n;for(;n!=0;n--){ cin>>m; count=0; for(j=1;j<=m;j++) cin>>s[j]; for(i=1;i<=m;i++) while(s[i]!=i) {j=s[i];temp=s[i];s[i]=s[j];s[j]=temp;count++;} cout<<count<<endl;}return 0;}
运行结果虽然正确,但是老超时,效率不高!在网上看到别人的程序,效率要提高很多:
#include<stdio.h>int main(){ int n,m,i,j,k,t; short p[10......
N!末尾一共有多少个0(2007-10-14 12:54:00)
摘要:#include "stdafx.h"#include <iostream>#include <math.h>using namespace std;int main(){int n,i;cin>>n;while(n){i=n/5+n/25+n/125+n/625;cout<<i<<endl;cin>>n;}return 0;}......
学生成绩管理系统(2007-10-14 12:50:00)
摘要:#include <stdio.h>#include <mem.h>#include <stdlib.h>#include <dos.h>#include <ctype.h>#include <alloc.h>#include <string.h>#define LEN sizeof(struct student)struct student{char num[6]; char name[6]; int score[3]; int sum; float average; int order; struct student *next;}head;int select(){int n;printf("********************************Welcome**************************************\n");printf("These below are your choices:\n");printf("\t\t1:Creat a text.\n");printf("\t\t2:Show the contents of the text.\n");printf("\t\t3:Search what you want in the system.\n");printf("\t\t4:Delete what you do not want to reserve.\n");printf("\t\t5:Insert the dates you insert.\n");printf("\t\t6:Sort these dates.\n");printf("\t\t7:Save these dates you insert.\n");printf("\t\t8:Load the dates from the file.\n");printf("\t\t9:Quit.\n");printf("********************************END*******************************************\n");printf("\t\tPle......
