matlab、2
来源:互联网 发布:840dsl调试软件 编辑:程序博客网 时间:2024/06/06 04:40
%% I. 清空环境变量及命令 clear all clc%% II. MATLAB编程习惯与风格 x_coordinate = rand(1,10); y_coordinate = rand(1,10); figure plot(x_coordinate,y_coordinate,'r-*')% 循环体的调试 a = 1:100; b = []; for i = 21:21 index = 105 - 5*i; b = [b a(index)]; end%%% 查看、编辑MATLAB自带的工具箱函数 edit mean edit newff%% IV. 向量化编程%%% 1. 及时清除不用的变量 a = rand(10000); b = rand(10000); clear a b = rand(10000);%%% 2. 按列优先循环 clear all clc n = 1000; a = rand(n); tic for i = 1:n for j = 1:n a(i,j); end end toc for i = 1:n for j = 1:n a(j,i); end end toc%%% 3. 循环次数多的变量安排在内层 clear all clc tic a = 0; for i = 1:1000 for j = 50000 a = a + 1; end end toc tic a = 0; for i = 1:50000 for j = 1:1000 a = a + 1; end end toc%%% 4. 给一些函数“瘦身” edit mean clear all clc a = rand(1,10000); tic b = mean(a) toc tic c = sum(a)/length(a) toc%% V. 图像对象和句柄%%% 1. 如何设置线条的属性呢? x = 0:0.01:2*pi; y = sin(x); h = plot(x,y); grid on get(h) set(h,'linestyle','-','linewidth',2,'color','k')% 2. 如何修改网格的间隔呢? set(gca,'xtick',0:0.5:7) set(gca,'ytick',-1:0.1:1)% 3. 如何设置图例的字体及大小呢? x = 0:0.01:2*pi; y1 = sin(x); y2 = cos(x); plot(x,y1,'r') hold on plot(x,y2,'-.b') h = legend('sin(x)','cos(x)'); set(h,'fontsize',16,'color','k','edgecolor','r','textcolor','w')%%% 4. 如何拆分图例呢? x = 0:0.01:2*pi; y1 = sin(x); y2 = cos(x); h1 = plot(x,y1,'r'); hold on h2 = plot(x,y2,'-.b'); ax1 = axes('position',get(gca,'position'),'visible','off'); legend(ax1,h1,'sin(x)','location','northwest') ax2 = axes('position',get(gca,'position'),'visible','off'); legend(ax2,h2,'cos(x)','location','northeast')
阅读全文
0 0
- matlab、2
- MATLAB中的一些小技巧(2) - [MATLAB]
- MATLAB入门教程2
- matlab 火力发电2
- matlab 中的 struct(2)
- matlab学习笔记 2
- MATLAB矩阵索引 2
- Matlab工具箱2
- Matlab tips 2
- matlab学习(2)
- Matlab------------命令大全2
- Matlab细节(2)
- matlab手记(2)
- matlab手记(2)
- MATLAB小贴士(2)
- matlab绘图2
- matlab:2 常用命令续
- matlab colormap详解 (2
- luogu 1425 小鱼的游泳时间
- 小程序request返回值真机和工具不一样,需要将字符串转为json
- hdu 3949 (线性基学习)
- matplotlib命令与格式:tick坐标轴主副刻度设置
- Javascipt学习笔记(Array对象)
- matlab、2
- mybatis简单学习
- 字符与字节有什么区别
- 我的编程之路
- [APUE]第四章文件和目录
- 求素数
- linux 中常用的命令
- Linux进程控制编程
- 面试抱佛脚