MATLAB
TODO list#
read list : https://www.zhihu.com/question/24499729
问题#
- [ ] matlab 为什么要有 cell 类型
待完成#
- [ ] xlsread 升级到 realcell
- [ ] 看 poly 系列函数, eg: polyfit
需求#
- [ ] 从本地文件上传
经常忘的#
- [ ] polyfit
经验 new#
string array 合并,要用 strjoin 不能 strcat
GUI#
回调函数不会监控值是否变化,只会用 event 触发变化。 要在 2020a 版本中删除回调函数,应在左侧“代码浏览器”中删除
笔记#
20200725#
错误见此 将 nested function 改为 local function。区别
20200726#
switch
语句在找到第一个符合条件的case
后,会忽略后面的case
20200727#
Convert array to argument list
func_to_call(cell_argin{:})
2020-8-1 05:29:43#
struc
和 sturct
不一样
后者才是新建结构体
struc Generate typical structure matrices for ARXSTRUC and IVSTRUC. NN = struc(NA,NB,NK) NA, NB and NK are vectors containing the orders na, nb and delays nk to be tested. See help on ARX for an explanation of na, nb and nk. NN is returned as a matrix containing all possible combinations of these orders and delays.
NN = struc(NA, NB_1, NB_2,..., NB_nu, NK_1, NK_2,..., NK_nu) Specify order combinations for a multi-input, single-output ARX model with nu inputs. The function thus takes 1+2*nu input arguments.
struc cannot handle multi-output cases.
1 总结 function 创建函数 f = inline('a * x * x + b * x + c', 'a', 'b','c', 'x')
生成矩阵 重复矩阵 Repmat 零矩阵 zeros 全1矩阵 ones(1,3) 1行3列
B=A.' 是转置 B=A' 是共轭转置
声明多个变量 >> x= sym('x',[2,1]) x =
x1 x2
1.1 集合 1.1.1 集合运算
matlab里关于集合运算和二进制数的运算的函数 intersect(A, B):集合交集,A和B均为向量 union(A, B) :集合并集 setdiff(A, B) :集合A减集合B的差集(如果集合A中的元素都在B中存在,则结果为空) ismember(a, A) :判断是否是集合中的元素 sort(A):对向量进行排序 issorted(A):判断集合是否有序 setxor :集合异或(在并集但不在交集中的元素) unique :返回集合的不重复元素(去掉相同元素)
1.2 矩阵 1.2.1 重排矩阵(可变为数列) reshape
1.3 多项式 1.3.1 化简多项式 simplify(F) 利用代数上的函数规则对表达式F进行化简 simple(F) 以尽可能的办法将F表达式再做化简,目的是使表达式以最少的字表示出 2019-6-30 6:29:20 上行失效 1.3.2 Symbol类型多项式和系数的相互转换 2019-6-29 08:08:14 有sym2poly 和 poly2sym
Symbol类和字符串的相互转换 2019-6-29 08:11:56 有str2sym(str)和sprintf('%s',sym)可用。
1.4 变量 1.4.1 Cell的索引:圆括号和花括号意义不同 2019年6月26日17:43:59 圆括号返回一个Cell,方括号返回Cell中的内容。 >> cellT={ 'a' , 'b'} cellT = 1×2 cell 数组 'a' 'b' >> cellT(1,1) ans = cell 'a' >> cellT{1,1} ans = a 1.4.2 struct的索引 用括号可以 将字符串变量转换为field 例如a.asdf=1; a.b=2; b='asdf'; 运行a.(b)=1. 1.4.3 声明变量==定义变量
%定义多个syms变量: for i=1:10 syms (['x',num2str(i)]); %x1、x2、x3。。。。 end
%定义多个空变量: for i=1:10 eval(['a',num2str(i),'=','[];']) %a1、a2、a3.。。。赋空值 end
%多个变量赋矩阵: for i=1:10 eval(['b',num2str(i),'=','rand(2,i);']) %b1、b2、b3.。。。赋矩阵数据 end
%sym叫符号变量
%矩阵符号变量 tag:符号矩阵 A=sym('a%d%d',[3,4])
handle = @(arglist)anonymous_function
1.4.4 变量名变化(带有动态序号的变量名) strst=strcat(strst,eval(['vx',num2str(1)]))
1.4.5 批量赋值 2018-6-25 02:49:45 [a,b,c]=deal(‘mat’,'lab’,'sky’)
1.4.6 从向量给多个变量批量赋值 2018-7-15 10:49:40 在看过deal,mat2cell(矩阵拆分转成元胞)的全部文档之后,在官网发现了num2cell,还是这个最方便。解决: clear ceTmp; ceTmp=num2cell(1-[nuAB,nuBB,nuCA]-[nuAC,nuBA,nuCC]); [nuAA,nuBC,nuCB]=ceTmp{:}
1.4.7 sym变量类型和double类型的区别 2019-10-14 04:25:05 1.4.7.1 精确度 a=1985613/0611565613574 b=sym(a) % == sym(1985613/0611565613574) c=sym(1985613)/sym(0611565613574 ) b^2-c^2 ans = -42693158387562469541515088677137279095/32581083816453932347972158670043787145501696088995612232658190336 1.4.7.2 Round函数
1.4.8 转换变量类型为数字 2019-1-30 20:55:03 int16() int8() 2019-7-3 06:01:29 double()
1.4.9 判断变量的类型: 2019-6-26 17:45:06 不要用 strcmp(‘cell’,class(var)),要用 iscell(var)
1.4.10 连接两个cell 2019-6-27 00:38:52 应用[cell1,cell2] 而不是 {cell1,cell2}(会返回一个1×2 的cell)
1.4.11 结构体 2019-7-3 04:56:10 请使用包含结构体的动态字段名称而不是getfield 以下命令等价getfield(struc,field) == struc.(field) 重点在括号 动态名称直接用 1.5 概率与统计 1.5.1 F分布和t分布问题 x=finv(1-α,n1,n2)----F(n1,n2)分布的上侧α分位数 x=tinv(1-α,n)----t(n)分布的上侧α分位数
x=chi2inv(1-α,n)------卡方分布(n)的上侧α分位数
f=@(x,y)@(a) x^2+y^+a; >> f1=f(2,3) f1 = @(a)x^2+y^+a >> f2=f1(4) f2 = 85
A(2,:)=[] %删除第2行
1.6 基本运算 1.6.1 化成分数 [maa,mab]=rats(max) max=maa./mab
rats(x,len)
1.6.2 分部分式:residue
2019-2-8 17:48:44
Partial fraction expansion (partial fraction decomposition)
[r,p,k] = residue(b,a)
[b,a] = residue(r,p,k)
分式 F(s) 可以表示为几个简单分式之和。
[r,p,k] 余项(部分分式展开式的残差) 极点(部分分式展开式的极点) 直项
此总和称为 F 的部分分式展开式。值 rm,...,r1 为残差,值 pm,...,p1 为极点,k(s) 为 s 多项式。对于大多数教科书问题,ks 为 0 或常量。
如果 p(j) = ... = p(j+m-1) 为 m 重极点,则展开式包括以下形式的项
Partfrac(symbolic function) 1.6.3 分数约分numden 2019-2-20 01:52:23 numden输入转换为其一项正性形式, 使分子和分母的最大公共除数为1。然后, 它返回表达式的该形式的分子和分母。
1.6.4 求函数零点 fzero
b = 2; c = 3.5; cubicpoly = @(x) x^3 + b*x + c; x = fzero(cubicpoly,0)
1.6.5 验证 -- Roots函数的返回值r 2019-6-24 01:10:38 (猜测) R应该是从大到小排列的,且重根会根据重数重复。 求多项式的根
1.6.6 多项式曲线拟合 2019-5-16 10:58:58 polyfit p = polyfit(x,y,n)
1.6.7 输入为数列的diff函数 2019-6-24 01:10:35 会返回下一个位置的标量和当前位置标量的差 例子: >> diff([5,3,10]) ans = -2 7 >> diff([5,3,10]') ans = -2 7
1.7 MATLAB函数 1.7.1 定义函数
matlab的全局变量用global声明,被该声明定义的变量可以被调用为全局变量。
函数名和m文件名可以不同,但是调用文件名才有用,只有第一个生效,后面的其他函数被认为是子函数,只能被该函数调用,不能直接被控制台调用。
1、函数文件+调用命令文件:需单独定义一个自定义函数的M文件; 2、函数文件+子函数:定义一个具有多个自定义函数的M文件;
3、Inline:无需M文件,直接定义;[[数值调用,不支持符号调用,但快。]] 4、匿名函数;使用matlab函数句柄操作符@,可以定义指向matlab内置函数和用户自定义函数的函数句柄,函数句柄也可以像函数一样的使用。例如:fh={@cos,@sin} 5、Syms+subs: 无需M文件,直接定义;[[用符号运算内核,运算速度会大大降低。]] 6、字符串+subs:无需M文件,直接定义; 当所要替代的符号在调用前都已经有了数值定义,则可以直接调用:subs(f) 7、直接通过@符号定义.[[可以构造多重匿名函数,每个@后的参数从它后面开始起作用,一直到表达式的最后。]]
1.7.2 可能未使用输入参数X,尽管使用了后一个参数。请考虑将其替换为~。 https://ww2.mathworks.cn/help/matlab/matlab_prog/ignore-function-inputs.html 此示例说明如何使用波浪号 (~) 运算符忽略函数定义中的输入。
当您的函数必须接受预定义的一组输入但不使用所有输入时,请使用该运算符。常见应用包括定义回调函数(如本文中所示)或从超类派生类。
----------------------正则表达式 regexprep('0+-5','[+][-]','-') 用-来替换连续的+- itfm也应该用这种方式替换 2018-6-23 22:59:17
---------------------switch中case的多选 用大括号完成,如下 chSolution='A' switch chSolution case {'a','A'} disp('good') end %switch 20180623
--------------------------if判断 2018-6-25 02:32:16 if a||b exp end 中 如果a为真,程序不检测b,就算b不存在也会运行exp。
1.8 MATLAB控制 1.8.1 if和for的跳出 If语句 打断 好像不能 For用break(while也是)终结,用continue进入下一个循环 Function用return终止
数组的If判断 Any和all。
向量场 quiver 2019-5-12 12:54:18 [x,y] = meshgrid(-2:0.2:2); dx = x.^2-3*x.y+y; dy = -5x+sin(x.*y); r = ( dx.^2 + dy.^2 ).^0.5; px = dx./r; py = dy./r; quiver(x,y,px,py);
1.8.2 跳出循环 break continue 2019-6-23 18:05:08 break 语句完全退出 for 或 while 循环。要跳过循环中的其余指令,并开始下一次迭代,请使用 continue 语句。
break 不是在 for 或 while 循环之外定义的。要退出函数,请使用 return。
1.8.3 暂停 break
1.8.4 计算运行时间 tic
程序内容
toc
1.8.5 尝试运行(try-catch): try, catch
1.9 自动化 1.9.1 模拟键盘、鼠标输入 How to Simulate keyboard key inputs? Java Robot class. KeyEvent.VK_W is the [W] key - there is no upper or lower case key! You need the [Shift] key to create uppercase characters: robot.keyPress(java.awt.event.KeyEvent.VK_SHIFT) robot.keyPress(java.awt.event.KeyEvent.VK_W) robot.keyRelase(java.awt.event.KeyEvent.VK_W) robot.keyRelease(java.awt.event.KeyEvent.VK_SHIFT) Remember: It is only a robot and it s(t)imulates the keyboard...
import java.awt.Robot; mouse = Robot; mouse.mouseMove(0, 0); screenSize = get(0, 'screensize'); for i = 1: screenSize(4) mouse.mouseMove(i, i); pause(0.00001); end
import java.awt.Robot; mouse = Robot; mouse.getPixelColor(378,645)
import win32api, win32con def click(x,y): win32api.SetCursorPos((x,y)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0) click(10,10)
模拟键盘:(粘贴快捷键) import java.awt.Robot; import java.awt.event.*; SimKey=Robot; SimKey.keyPress(java.awt.event.KeyEvent.VK_CONTROL); SimKey.keyPress(java.awt.event.KeyEvent.VK_C); SimKey.keyRelease(java.awt.event.KeyEvent.VK_CONTROL);
键盘常量 键名 键盘常量 键盘常量 VK_CONTROL 控制键 VK_UP 上箭头 VK_SHIFT shift键 VK_DOWN 下箭头 VK_BACK_SPACE 退格键 VK_LEFT 左箭头 VK_ENTER 回车键 VK_RIGHT 右箭头 VK_SPACE 空格键 VK_ESCAPE Esc键 VK_F1- -VK_F12 F1- -F12 VK_TAB Tab键 VK_0 - -VK_9 0- -9 VK_PGUP page up键 VK_A - -VK_Z A- -Z VK_PGDN page down键 VK_SEMICOLON 分号 “;” VK_PERIOD 句点 “.” K_UNDERSCORE 下划线 “_” VK_COMMA 逗号 “,”
1.9.2 等待按键
等待按键e: while 1 pause(0.3) fprintf('wf\n') if strcmpi(get(gcf,'CurrentCharacter'),'e') break; end
等待任意按键:不能是功能键
w = waitforbuttonpress;
if w
p = get(gcf, 'CurrentCharacter');
disp(p) %displays the character that was pressed
disp(double(p)) %displays the ascii value of the character that was pressed
end
pause
1.10 字符串 1.10.1 字符串操作
strcat,字符水平相连 strvcat,字符垂直相连
strst=strcat(strst,eval(['vx',num2str(1)]))
a='wenjian'; b='.txt'; c=strcat(a,b) c = wenjian.txt c=strvcat(a,b) c = wenjian .txt
%数字可以通过num2str函数将其转换为字符串后与字符相连。
a=3;c=strcat(num2str(a),b) c = 3.txt
sprintf???
1.10.2 转义字符 fprintf %A 浮点数、十六进制数字和p-记法(C99) %c 一个字符 %d 有符号十进制整数 %e 浮点数、e-记数法 %E 浮点数、E-记数法 %f 浮点数、十进制记数法 %g 根据数值不同自动选择%f或%e. %G 根据数值不同自动选择%f或%e. %i 有符号十进制数(与%d相同) %o 无符号八进制整数 %p 指针 %s 字符串 %u 无符号十进制整数 %x 使用十六进制数字0f的无符号十六进制整数 %X 使用十六进制数字0f的无符号十六进制整数 %% 打印一个百分号 //还有一个特殊的格式%. ,这两个星号的值分别由第二个和第三个参数的值指定 printf("%.*s \n", 8, "abcdefgggggg"); fprintf('%.*s \n', 8, 'abcdefgggggg')
eval中的fprintf中的%不用转译,引号需要
===========================================#
==================问题===================
rats(0.142857)
ans =
*
字符串?
nargout ans = 1547376 ???
repmat
fprintf输出是 2.5e+03 in tip2
function中可以改变向量的值,但function中的function不能 eg: function a1muti100(a) a(1)=a(1)*100 a1multi2(a) %是否运行此行不改变运行结果 end function a1multi2(a) a(1)=a(1))*2 end
==================================fprintf disp转义字符 两个(还是三个?2018-6-25 03:14:01)'=输出中的' 'First calling variable is ''' s '''.'
-------------------------fprintf中的小数格式(??) '%s%.*f;
================================匿名函数 f = @(t) -4t^2+30t+32
==================================symbol转换为num 转换为数字 double(X)
=============================isinteger 判断的是变量类型而非该变量的数值是否为整数 2018-6-17 13:26:13 应该用什么?
1.10.3 Regexp 还有tokens,match,split等用法 2018-6-25 03:01:21 漏记了regex的用法,下次看说明补上 2019-7-4 10:23:20 补充 元字符 元字符表示字母、字母范围、数字和空格字符。使用它们来构造广义的字符模式。 元字符 说明 示例 . 任何单个字符,包括空白 '..ain' 与以 'ain' 结尾的五个连续字符序列匹配。 [c1c2c3] 包含在方括号中的任意字符。下列字符将按字面意义进行处理:$ | . * + ? 和 -(不用于指示范围时)。 '[rp.]ain' 与 'rain'、'pain' 或 '.ain' 匹配。 [^c1c2c3] 未包含在方括号中的任意字符。下列字符将按字面意义进行处理:$ | . * + ? 和 -(不用于指示范围时)。 '[^rp]ain' 与以 'ain' 结尾的所有由四个字母组成的序列('rain'、'pain' 和 'ain' 除外)匹配。例如,它与 'gain'、'lain' 或 'vain' 匹配。 [c1-c2] c1 到 c2 范围中的任意字符 '[A-G]' 与 A 到 G 范围中的单个字符匹配。 \w 任意字母、数字或下划线字符。对于英语字符集,\w 等同于 [a-zA-Z_0-9] '\w' 标识一个单词。 \W 字母、数字或下划线之外的任意字符。对于英语字符集,\W 等同于 [^a-zA-Z_0-9] '\W*' 标识非单词项。 \s 任意空白字符;等同于 [ \f\n\r\t\v] '\wn\s' 与以字母 n 结尾且后跟空白字符的单词匹配。 \S 任意非空白字符;等同于 [^ \f\n\r\t\v] '\d\S' 与数字(后跟任意非空白字符)匹配。 \d 任意数字;等同于 [0-9] '\d*' 与任意数量的连续数字匹配。 \D 任意非数字字符;等同于 [^0-9] '\w*\D>' 与不以数字结尾的单词匹配。 \oN 或 \o{N} 八进制值 N 的字符 '\o{40}' 与八进制 40 定义的空格字符匹配。 \xN 或 \x{N} 十六进制值 N 的字符 '\x2C' 与十六进制 2C 定义的逗号字符匹配。 太多了,帖链接 https://ww2.mathworks.cn/help/matlab/ref/regexp.html?s_tid=doc_ta https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_Expressions
1.10.4 正则表达式中逗号的转义字符 没有,因为不需要。
1.10.5 matlab中所有的转义字符。
Escape characters, including:
'' Single quotation mark %% Percent character \ Backslash \a Alarm \b Backspace \f Form feed \n New line \r Carriage return \t Horizontal tab \v Vertical tab \xN Hexadecimal number, N \N Octal number, N
1.10.6 需要补充 - 正则表达式的转义字符
如: * \ \D
1.11 逻辑、判断 和 对比 1.11.1 All 和 Any 对 向量的任一向量元素 或 向量的全部元素 的判断 可以借助all()和any() 实际上是一列logical向量的 且、或 eg: all([nuAB,nuBB,nuBA,nuCA,nuAC,nuCC]>=.5)
1.11.2 空字符串/数组对比 []=='' or ''==[] 逐字返回,返回值为[]
===============================如果可以执行(类似Python try) try一般与catch连用,表示选择判断。 try (command1)组命令1总被执行,错误时跳出此结构 catch (command2)仅当组命令1出现错误时组命令2才被执行 end
1.11.3 判断数列相等 isequal (只返回1或0,不逐字对比) isequaln (视NaN相同)
1.11.4 筛选和替换(简单版)
A=max(A,0)
pos=find(A==-32) A(pos)=0 此处pos可以是数列
筛选 find(20\<A&A\<30)
isempty > length==0
替换(简洁版) ar_2en(find(ar_2en==-32))=0
return:停止运行子程序(m文件)
\b 退格(BS) ,将当前位置移到前一列 008 \n 换行(LF) ,将当前位置移到下一行开头(有可能不是开头而是当前字符位置,可能和\r连用) 010 \r 回车(CR) ,将当前位置移到本行开头 013
\a 响铃(BEL) 007
\f 换页(FF),将当前位置移到下页开头 012
\t 水平制表(HT) (跳到下一个TAB位置) 009
\v 垂直制表(VT) 011
\ 代表一个反斜线字符''' 092
' 代表一个单引号(撇号)字符 039
" 代表一个双引号字符 034
\0 空字符(NULL) 000
\ddd 1到3位八进制数所代表的任意字符 三位八进制
\xhh 1到2位十六进制所代表的任意字符 二位十六进制
inv(A)B \< A\B Binv(A) \< B/A
1.11.5 大于某数的统计 sum(vector>k) 求vector中大于k的数的数量。
1.11.6 空值判断 if isempty(a) 可以
1.11.7 Cell对比 2019-3-27 04:11:17 用isequal函数
1.12 输入和输出 1.12.1 分别输出: 将向量变为列向量 fprintf('%f s, the velocity is %f m/s, the height is %f m\n', [t; vt; ht]);
1.12.2 提示输入 nuCoeX = input('P=??x+??y ?');
1.13 外部命令 1.13.1 执行dos命令
status = dos(command) [status,cmdout] = dos(command) [status,cmdout] = dos(command,'-echo') status=dos( ' notepad & ' )
k = waitforbuttonpress blocks the caller's execution stream until the function detects that the user has clicked a mouse button or pressed a key while the figure window is active. The figure that is current when you call the waitforbuttonpress function is the only area in which users can press a key or click a mouse button to resume program execution. The return argument, k, can have these values:
0 if it detects a mouse button click 1 if it detects a key press Here are some important points to consider when using the waitforbuttonpress function:
If a WindowButtonDownFcn callback is defined for the figure, its callback is executed before waitforbuttonpress returns a value. These Figure properties provide additional information about the user’s interaction with the window: CurrentCharacter, SelectionType, and CurrentPoint. Pressing keys that generate characters can cause the function to return. Pressing any of the following keys by itself does nothing: Ctrl, Shift, Alt, Caps_lock, Num_lock, Scroll_lock. The waitforbuttonpress function errors if the user closes the figure by clicking the X (close box) unless your code calls the waitforbuttonpress function within a try/catch block. The behavior of the waitforbuttonpress function changed in R2014b. The figure that is current when you call the waitforbuttonpress function is the only area in which users can press a key or click a mouse button to resume program execution.
1.13.2 MsgBox msgbox('input error','error');
1.13.3 打开网页 web www.baidu.com
1.13.4 运行批处理指令 %tag#batch 例如重命名: eval('!help ren') 等效于在cmd中输入 help ren
1.14 文件
C:\Users\自己的用户名\AppData\Roaming\MathWorks\MATLAB
直接\会放在根目录下 .\是当前浏览的目录。 ..\是当前浏览目录的上一级。 还是要mfilename
来源:http://blog.sina.com.cn/s/blog_72827fb10101i6bh.html 当前路径下 (mat和m文件在一起): load *.mat; 在下一级路径下: load .\下一级路径的文件名*.mat; 在上一级路径下: load ..*.mat; 在平行文件夹内: load ..\平行的文件夹*.mat;
例如,读写当前目录下aaaa文件夹中的x.txt文件 fid = fopen('.\aaaa\x.txt', 'wt'); fprintf(fid, '%s\n', '1234'); fclose(fid);
在上两(或若干级)路径下: s = pwd; % 获取当前路径 cd('..'); % 跳到上一级路径下 load ..\asd\sdfg***.mat % 获取上上级路径下的文件 cd(s); % 返回之前的路径 即可。
1.15 MATLAB易用性改善 1.15.1 警告:名称不存在或不是目录: 2019-2-22 03:22:28 解决方法: 命令窗口中输入>> edit pathdef.m 将错误路径删除即可。
2 心得、经验、纪律
2.1 命名法
2017-9-30 14:42:58 ar array va value nu number in integer st string sy symbol mx mixed format ve vector sa symbol array
2017-10-3 16:09:04 va 与 ve 太像,改用nu 和 ar
之前是 arr_ v_ n_ int_ str_ 相比起来输入时省事了,对可读性的影响应该不大吧
3 模板 3.1 IVY统一模板-IVY TEMPLATE-211模板-212模板-212FUNCTIONS 2020-5-15 17:47:11 已移动到matlab\dev
function i212c212p502033(varargin) %ivy MATH 212 5.2.33 - %created 20190916 % %% Input clear ceIn ; if 0 == nargin clear arIn ; arIn=input('[A,B,C,D,E,F] of d/dx( ) \n'); ceIn = num2cell(arIn); else ceIn = varargin; end%if [nuA,nuB,nuC,nuD,nuE,nuF]=ceIn{:};
1 2 3 4 5 |
|
% stOut2 = sprintf('',... % ); % stOut3 = sprintf('',... % ); % stOut4 = sprintf('',... % );
1 2 3 |
|
% stOut2=itfAll(stOut2); % tPaste(stOut2); % tPaste(stOut3); % tPaste(stOut4); fprintf('DONE\n'); end%func
3.2 输入提示(INPUT PROMPTS)
limit{ ,x-> }
3.3 135原输入为数组,新输入为拆分后的数组
注意:1.改 变量数
2改 区间起点终点和长度
3 添加 ,varargin
2019-5-6 04:00:28
%% automation if 5 == nargin fprintf('AUTOMATION MODE\n'); arFrequency=[nuInterval1Start,nuInterval1End,nuIntervalLastStart,arFrequency,varargin]; arFrequency=cell2mat(arFrequency); [nuInterval1Start,nuInterval1End,nuIntervalLastStart]=deal(799.5,899.5,1199.5); end%if %% automation end 3.4 % 给 无输入 加输入 if 0 == nargin basicToolTurn('i901059old'); elseif 3 == nargin clear arTmp; arTmp = cell2mat(varargin); i901059old(arTmp(1),arTmp(2),arTmp(3)); end%if
3.5 135模板 function i135c135p60109 (varargin) %ivy MATH 135 course name 135 6.1. - %created 20190330 % %% Input if 0 == nargin clear arIn ; arIn=input('[A,B,C,D,E,F] of '); clear ceIn ; ceIn = num2cell(arIn); [nuA,nuB,nuC,nuD,nuE,nuF]=ceIn{:}; elseif 2 == nargin clear ceIn ; ceIn = varargin; [nuA,nuB]=ceIn{:}; end%if %% Calculate clear stOut nuOut; syms x;
1 2 3 4 5 6 |
|
end %function
3.6 弃用的程序添加提示 for i=1:9 fprintf('ELIMINATED RENAMED: -> !!!\n'); end%for
3.7 SHOW IMAGE 展示图片
1 2 3 |
|
3.8 SIN / COS if strcmp(stIn2 , 'cos') || strcmp(stIn2 , 'c') stSign='+'; elseif strcmp(stIn2 , 'sin') || strcmp(stIn2 , 's') stSign='-'; else error('输入的函数名称错误\n'); end%if
3.9 INPUT BLOCK
%% Input
clear arIn ;
arIn=input('[A,B,C,D,E] of P=Ax1+Bx2;x1+x2\<=C;x1+Dx2\<=E');
%
clear ceIn ;
ceIn = num2cell(arIn);
[nuA,nuB,nuC,nuD,nuE]=ceIn{:};
%
3.10 INPUT2 %% Handle Input fprintf('Input Available'); if 0 == nargin = input(' ?'); = input(' and?'); = input(' and?'); end%if %%
跳转 function i0050 %ivy MATH 212 - %ivymath135 10.5. - %created 20190122 % comment inside % NO comment basicToolTurn(''); fprintf('DONE\n'); fprintf('TURNED\n'); end %function
(nu11,nu12,nu21,nu22) (nu11,nu12,nu13,nu21,nu22,nu23) (nu11,nu12,nu13,nu14,nu21,nu22,nu23,nu24) (nu11,nu12,nu13,nu21,nu22,nu23,nu31,nu32,nu33) (nuCoe11,nuCoe12,nuCoe13,nuRHS1,nuCoe21,nuCoe22,nuCoe23,nuRHS2,nuCoe31,nuCoe32,nuCoe33,nuRHS3)
------------------------------------------����---�����β fprintf('DONE\n'); end %function
%update - 20180623 : rename
%-------------------------------------------������
for i=1:3
fprintf('RENAME! to tSecPaste\n')
end%for
%-------------------------------------------Marcov��ͼ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
%-------------------------------------------Marcov��ͼ
===================================================δ֪��; ------------------------------------------��ͼ
vq=solve(diff(f)), vpa(subs(f,q, )) y=(subs(f,q,x)); plot(x,y)
======================================================�Ѿ���Ϊ�������ã��浵��
------------------------���� format long g format compact warning off
fprintf('\n');
-------------------------------������ ,arr_rst(1),arr_rst(2),arr_rst(3),arr_rst(4),arr_rst(5),arr_rst(6),arr_rst(7),arr_rst(8),arr_rst(9)
----------------------------��������ױ�� function i83 %ivy unit 8.3 : 8.5.
1 2 |
|
%output fprintf('\npress any key to start autoinput...\n(Ctrl+C to quit)\n'); pause;pause(1); tpaste(nurst,'Enter'); fprintf('Autoinput finished\n\n'); end %function
����������ַ�����#
%output fprintf('\npress any key to start autoinput...\n(Ctrl+C to quit)\n'); pause;pause(1); tpaste(arrst(nucnt)|nurst,'Enter'); fprintf('Autoinput finished\n\n'); end %function
������ͣ���
%output clear nulenrst; nulenrst=length(arrst); fprintf('\npress any key to start autoinput...\n(Ctrl+C to quit)\n'); pause;pause(1); for nucnt=1:nulenrst tpaste(arrst(nucnt)); end%for fprintf('Autoinput finished\n\n'); end %function
�����ͣ���
%output clear nulenrst; nulenrst=length(arrst); for nucnt=1:nulenrst fprintf('\npress any key to start autoinput...\n(Ctrl+C to quit)\n'); pause;pause(1); tpaste(arrst(nucnt)); end%for fprintf('Autoinput finished\n\n'); end %function
--------------------------------------�������� %output clear nurow nucol; [nurow,nucol]=size(marst); for nucntcol=1:nucol fprintf('\npress any key to start autoinput...\n(Ctrl+C to quit)\n'); pause;pause(1); for nucntrow=1:nurow tpaste(marst(nucntrow,nucntcol)); end%for fprintf('Autoinput finished\n\n'); end %function
--------New Quiz-------------- function %ivymath135 Quiz Module 11 (8.3-.8.5) %created 20180716
1 |
|
end %function
--------- rename 20190205 --------
% update 20190205 - rename : to
for i = 1:3
fprintf('RENAMED TO \n');
end%for
4 问题 R2016b
round(double(mean([50 90 190 347 127 83 91 164]/10)),2) ans = 14.27 round(double(mean([50 90 190 347 127 84 90 164]/10)),2) ans = 14.28 round(double(sum([50 90 190 347 127 84 90 164]/10)/8),2) ans = 14.28 round(double(sum([50 90 190 347 127 83 91 164]/10)/8),2) ans = 14.27
-.4997--.4998 ans = 0.000100000000000045 -.4997+.5 ans = 0.000300000000000022 -.4998+.5 ans = 0.000199999999999978
-0.00010000000000004449773882697627414
问题2
det([-8,2;12,-3]) ans = -1.33226762955019e-15
问题3 >> f=x^3/4-x^2/3-x/2+3cos(x) >> fun = @(x) subs(f,x) >> fzero(fun,-1) ans = -0.971715728752539 >> fun = @(x) 3cos(x) - x/2 - x^2/3 + x^3/4 >> fzero(fun,-1) ans = -1.37312166467604
==== 2019-5-16 22:41:06 >> log(10/15)/-60 - log(3/2)/60 ans = 8.67361737988404e-19
=== 2*.412+25*-24/25 ans = 1.77635683940025e-15
5 疑问 如何调整输出图像的大小,使其保持高宽比 如在i212c201p501011中。