控制命令窗口输入和输出
2013-04-16 21:04
344 查看
控制命令窗口输入和输出
迄今为止,你已经使用MATLAB命令行,键入函数和表达式,并且查看打印在命令窗口中的结果。这部分描述了
(1)格式函数
(2)压制输出
(3)输入长语句
(4)命令行编辑
一、格式函数
格式函数控制通过MATLAB显示的变量的数值格式。函数仅影响如何显示数,不会影响MATLAB的计算或保存它们。这里不同的格式,共同输出一个变量X的结果
注意:确认适当间隔,使用一个固定宽,例如书信。
x=[4/31.2345e-6]
短格式
1.3333 0.0000
e的短格式
1.3333e+000 1.2345e-006
g的短格式
1.3333 1.2345e-006
长格式
1.33333333333333 0.00000123450000
e的长格式
1.333333333333333e+000 1.234500000000000e-006
g的长格式
1.33333333333333 1.2345e-006
银行格式
1.33 0.00
分数格式
4/3 1/810045
十六进制格式
3ff5555555555555 3eb4b6231abfd271
如果一个矩阵的最大元素超过10^3或小于10^3,MATLAB为短和长格式应用一个命令尺度因子。
并且格式函数显示在上面
格式简化
在输出中压制空白行的许多应用。这让你在一个屏幕或窗口上看到更多信息。如果你向更多控制输出格式。使用sprintf和fprintf函数。
二、压制输出
如果你简单键入一个语句并按返回或确认,MATLAB在屏幕上自动显示结果。不过,如果你用分号作为行的结束,MATLAB执行计算但是不会显示任何输出。当你产生一个大型矩阵时,这是细节的使用。例如
A=magic(100);
三、输入长语句
如果一个语句在一行上不合适,是用一个省略(三个点),...,返回或确认以下表示语句连续在下一行上。例如
s=1-1/2+1/3-1/4+1/5-1/6+1/7...
-1/8+1/9-1/10+1/11-1/12;
空白间隔周围的=,+和-单精度操作符,但是它们改善了阅读性。</FONT>
四、命令行编辑
各种命令语句可以通过你键盘上的控制键位进行回顾,并且重复使用你更早键入的语句。例如,假设你错误键入
rho=(1+sqt(5))/2
你已经错误键入sqrt。MATLAB回显
Undefinedfunctionorvariable'sqt'.
不能定义函数或变量'sqrt'。
重复键入代替整个行,简单按上方向()键。你键入过的语句重复显示。使用左方向()键去移动光标覆盖和插入缺少的'r'。再次使用上方向()键回顾以前的行。键入一个字符然后用上方向()键查找一个以往的行。你也可以中命令历史中复制命令语句,查看命令历史。
下面是在命令窗口中允许你键入的控制键位。如果你喜欢使用Ctrl+key的键位去命令显示,也可以在偏好设置中进行设置。了解如何设置请查阅在MATLAB开发环境文档中的一般桌面工具的键盘快捷键。
键位控制键操作上方向键Ctrl+P回顾以往键入的命令,仅仅在命令行中有效下方向键Ctrl+N
回顾下一行键入的命令,仅在命令行中,如果你已经使用过上方向键或Ctrl+P。
左方向键Ctrl+B向左移动光标一个字符右方向键Ctrl+F向右移动光标一个字符Ctrl+右方向键 光标移动到一个词的开始Ctrl+左方向键光标移动到一个词的结束HomeCtrl+A光标移动到一行的开始EndCtrl+E光标移动到一行的结束Ctrl+Home 光标移动到一行的最左端Ctrl+EndCtrl+U光标移动到一行的最右端EscCtrl+D删除光标所在的一行DeleteCtrl+H删除光标右边一个字符Backspace删除光标左边的一个字符Ctrl+K删除光标右边的所有字符Shift+Home 选中光标左边的全部字符Shift+End 选中光标右边的全部字符
ControllingCommandWindowInputandOutput
Sofar,youhavebeenusingtheMATLABcommandline,typingfunctionsandexpressions,andseeingtheresultsprintedintheCommandWindow.Thissectiondescribes
(1)TheformatFunction
(2)SuppressingOutput
(3)EnteringLongStatements
(4)CommandLineEditing
一、TheformatFunction
TheformatfunctioncontrolsthenumericformatofthevaluesdisplayedbyMATLAB.Thefunctionaffectsonlyhownumbersaredisplayed,nothowMATLABcomputesorsavesthem.Herearethedifferentformats,togetherwiththeresultingoutputproducedfromavectorxwithcomponentsofdifferentmagnitudes.
Note Toensureproperspacing,useafixed-widthfont,suchasCourier.
x=[4/31.2345e-6]
formatshort
1.3333 0.0000
formatshorte
1.3333e+000 1.2345e-006
formatshortg
1.3333 1.2345e-006
formatlong
1.33333333333333 0.00000123450000
formatlonge
1.333333333333333e+000 1.234500000000000e-006
formatlongg
1.33333333333333 1.2345e-006
formatbank
1.33 0.00
formatrat
4/3 1/810045
formathex
3ff5555555555555 3eb4b6231abfd271
Ifthelargestelementofamatrixislargerthan10^3orsmallerthan10^(-3),MATLABappliesacommonscalefactorfortheshortandlongformats.
Inadditiontotheformatfunctionsshownabove
formatcompact
suppressesmanyoftheblanklinesthatappearintheoutput.Thisletsyouviewmoreinformationonascreenorwindow.Ifyouwantmorecontrolovertheoutputformat,usethesprintfandfprintffunctions.
二、SuppressingOutput
IfyousimplytypeastatementandpressReturnorEnter,MATLABautomaticallydisplaystheresultsonscreen.However,ifyouendthelinewithasemicolon,MATLABperformsthecomputationbutdoesnotdisplayanyoutput.Thisisparticularlyusefulwhenyougeneratelargematrices.Forexample,
A=magic(100);
三、EnteringLongStatements
Ifastatementdoesnotfitononeline,useanellipsis(threeperiods),...,followedbyReturnorEntertoindicatethatthestatementcontinuesonthenextline.Forexample,
s=1-1/2+1/3-1/4+1/5-1/6+1/7...
-1/8+1/9-1/10+1/11-1/12;
Blankspacesaroundthe=,+,and-signsareoptional,buttheyimprovereadability.
四、CommandLineEditing
Variousarrowandcontrolkeysonyourkeyboardallowyoutorecall,edit,andreusestatementsyouhavetypedearlier.Forexample,supposeyoumistakenlyenter
rho=(1+sqt(5))/2
Youhavemisspelledsqrt.MATLABrespondswith
Undefinedfunctionorvariable'sqt'.
Insteadofretypingtheentireline,simplypressthekey.Thestatementyoutypedisredisplayed.Usethekeytomovethecursoroverandinsertthemissingr.Repeateduseofthekeyrecallsearlierlines.Typingafewcharactersandthenthekeyfindsapreviouslinethatbeginswiththosecharacters.YoucanalsocopypreviouslyexecutedstatementsfromtheCommandHistory.Formoreinformation,seeCommandHistory.
FollowingisthelistofarrowandcontrolkeysyoucanuseintheCommandWindow.IfthepreferenceyouselectforCommandlinekeybindingsisEmacs(MATLABstandard),youcanalsousetheCtrl+keycombinationsshown.SeealsogeneralkeyboardshortcutsfordesktoptoolsintheMATLABDevelopmentEnvironmentdocumentation.
Key ControlKeyforEmacs(MATLABstandard)Preference Operation Ctrl+P Recallpreviousline.Worksonlyatcommandline. Ctrl+N Recallnextline.WorksonlyatcommandlineifyoupreviouslyusedtheuparroworCtrl+P. Ctrl+B Movebackonecharacter. Ctrl+F Moveforwardonecharacter. Ctrl+ Moverightoneword. Ctrl+ Moveleftoneword. Home Ctrl+A Movetobeginningofcommandline. End Ctrl+E Movetoendofcommandline. Ctrl+Home MovetotopofCommandWindow. Ctrl+End MovetoendofCommandWindow. Esc Ctrl+U Clearcommandline. Delete Ctrl+D Deletecharacteratcursorincommandline. Backspace Ctrl+H Deletecharacterbeforecursorincommandline. Ctrl+K Cutcontents(kill)toendofcommandline. Shift+Home Highlighttobeginningofcommandline. Shift+End Highlighttoendoflastline.CanstartatanylineintheCommandWindow.
迄今为止,你已经使用MATLAB命令行,键入函数和表达式,并且查看打印在命令窗口中的结果。这部分描述了
(1)格式函数
(2)压制输出
(3)输入长语句
(4)命令行编辑
一、格式函数
格式函数控制通过MATLAB显示的变量的数值格式。函数仅影响如何显示数,不会影响MATLAB的计算或保存它们。这里不同的格式,共同输出一个变量X的结果
注意:确认适当间隔,使用一个固定宽,例如书信。
x=[4/31.2345e-6]
短格式
1.3333 0.0000
e的短格式
1.3333e+000 1.2345e-006
g的短格式
1.3333 1.2345e-006
长格式
1.33333333333333 0.00000123450000
e的长格式
1.333333333333333e+000 1.234500000000000e-006
g的长格式
1.33333333333333 1.2345e-006
银行格式
1.33 0.00
分数格式
4/3 1/810045
十六进制格式
3ff5555555555555 3eb4b6231abfd271
如果一个矩阵的最大元素超过10^3或小于10^3,MATLAB为短和长格式应用一个命令尺度因子。
并且格式函数显示在上面
格式简化
在输出中压制空白行的许多应用。这让你在一个屏幕或窗口上看到更多信息。如果你向更多控制输出格式。使用sprintf和fprintf函数。
二、压制输出
如果你简单键入一个语句并按返回或确认,MATLAB在屏幕上自动显示结果。不过,如果你用分号作为行的结束,MATLAB执行计算但是不会显示任何输出。当你产生一个大型矩阵时,这是细节的使用。例如
A=magic(100);
三、输入长语句
如果一个语句在一行上不合适,是用一个省略(三个点),...,返回或确认以下表示语句连续在下一行上。例如
s=1-1/2+1/3-1/4+1/5-1/6+1/7...
-1/8+1/9-1/10+1/11-1/12;
空白间隔周围的=,+和-单精度操作符,但是它们改善了阅读性。</FONT>
四、命令行编辑
各种命令语句可以通过你键盘上的控制键位进行回顾,并且重复使用你更早键入的语句。例如,假设你错误键入
rho=(1+sqt(5))/2
你已经错误键入sqrt。MATLAB回显
Undefinedfunctionorvariable'sqt'.
不能定义函数或变量'sqrt'。
重复键入代替整个行,简单按上方向()键。你键入过的语句重复显示。使用左方向()键去移动光标覆盖和插入缺少的'r'。再次使用上方向()键回顾以前的行。键入一个字符然后用上方向()键查找一个以往的行。你也可以中命令历史中复制命令语句,查看命令历史。
下面是在命令窗口中允许你键入的控制键位。如果你喜欢使用Ctrl+key的键位去命令显示,也可以在偏好设置中进行设置。了解如何设置请查阅在MATLAB开发环境文档中的一般桌面工具的键盘快捷键。
键位控制键操作上方向键Ctrl+P回顾以往键入的命令,仅仅在命令行中有效下方向键Ctrl+N
回顾下一行键入的命令,仅在命令行中,如果你已经使用过上方向键或Ctrl+P。
左方向键Ctrl+B向左移动光标一个字符右方向键Ctrl+F向右移动光标一个字符Ctrl+右方向键 光标移动到一个词的开始Ctrl+左方向键光标移动到一个词的结束HomeCtrl+A光标移动到一行的开始EndCtrl+E光标移动到一行的结束Ctrl+Home 光标移动到一行的最左端Ctrl+EndCtrl+U光标移动到一行的最右端EscCtrl+D删除光标所在的一行DeleteCtrl+H删除光标右边一个字符Backspace删除光标左边的一个字符Ctrl+K删除光标右边的所有字符Shift+Home 选中光标左边的全部字符Shift+End 选中光标右边的全部字符
ControllingCommandWindowInputandOutput
Sofar,youhavebeenusingtheMATLABcommandline,typingfunctionsandexpressions,andseeingtheresultsprintedintheCommandWindow.Thissectiondescribes
(1)TheformatFunction
(2)SuppressingOutput
(3)EnteringLongStatements
(4)CommandLineEditing
一、TheformatFunction
TheformatfunctioncontrolsthenumericformatofthevaluesdisplayedbyMATLAB.Thefunctionaffectsonlyhownumbersaredisplayed,nothowMATLABcomputesorsavesthem.Herearethedifferentformats,togetherwiththeresultingoutputproducedfromavectorxwithcomponentsofdifferentmagnitudes.
Note Toensureproperspacing,useafixed-widthfont,suchasCourier.
x=[4/31.2345e-6]
formatshort
1.3333 0.0000
formatshorte
1.3333e+000 1.2345e-006
formatshortg
1.3333 1.2345e-006
formatlong
1.33333333333333 0.00000123450000
formatlonge
1.333333333333333e+000 1.234500000000000e-006
formatlongg
1.33333333333333 1.2345e-006
formatbank
1.33 0.00
formatrat
4/3 1/810045
formathex
3ff5555555555555 3eb4b6231abfd271
Ifthelargestelementofamatrixislargerthan10^3orsmallerthan10^(-3),MATLABappliesacommonscalefactorfortheshortandlongformats.
Inadditiontotheformatfunctionsshownabove
formatcompact
suppressesmanyoftheblanklinesthatappearintheoutput.Thisletsyouviewmoreinformationonascreenorwindow.Ifyouwantmorecontrolovertheoutputformat,usethesprintfandfprintffunctions.
二、SuppressingOutput
IfyousimplytypeastatementandpressReturnorEnter,MATLABautomaticallydisplaystheresultsonscreen.However,ifyouendthelinewithasemicolon,MATLABperformsthecomputationbutdoesnotdisplayanyoutput.Thisisparticularlyusefulwhenyougeneratelargematrices.Forexample,
A=magic(100);
三、EnteringLongStatements
Ifastatementdoesnotfitononeline,useanellipsis(threeperiods),...,followedbyReturnorEntertoindicatethatthestatementcontinuesonthenextline.Forexample,
s=1-1/2+1/3-1/4+1/5-1/6+1/7...
-1/8+1/9-1/10+1/11-1/12;
Blankspacesaroundthe=,+,and-signsareoptional,buttheyimprovereadability.
四、CommandLineEditing
Variousarrowandcontrolkeysonyourkeyboardallowyoutorecall,edit,andreusestatementsyouhavetypedearlier.Forexample,supposeyoumistakenlyenter
rho=(1+sqt(5))/2
Youhavemisspelledsqrt.MATLABrespondswith
Undefinedfunctionorvariable'sqt'.
Insteadofretypingtheentireline,simplypressthekey.Thestatementyoutypedisredisplayed.Usethekeytomovethecursoroverandinsertthemissingr.Repeateduseofthekeyrecallsearlierlines.Typingafewcharactersandthenthekeyfindsapreviouslinethatbeginswiththosecharacters.YoucanalsocopypreviouslyexecutedstatementsfromtheCommandHistory.Formoreinformation,seeCommandHistory.
FollowingisthelistofarrowandcontrolkeysyoucanuseintheCommandWindow.IfthepreferenceyouselectforCommandlinekeybindingsisEmacs(MATLABstandard),youcanalsousetheCtrl+keycombinationsshown.SeealsogeneralkeyboardshortcutsfordesktoptoolsintheMATLABDevelopmentEnvironmentdocumentation.
Key ControlKeyforEmacs(MATLABstandard)Preference Operation Ctrl+P Recallpreviousline.Worksonlyatcommandline. Ctrl+N Recallnextline.WorksonlyatcommandlineifyoupreviouslyusedtheuparroworCtrl+P. Ctrl+B Movebackonecharacter. Ctrl+F Moveforwardonecharacter. Ctrl+ Moverightoneword. Ctrl+ Moveleftoneword. Home Ctrl+A Movetobeginningofcommandline. End Ctrl+E Movetoendofcommandline. Ctrl+Home MovetotopofCommandWindow. Ctrl+End MovetoendofCommandWindow. Esc Ctrl+U Clearcommandline. Delete Ctrl+D Deletecharacteratcursorincommandline. Backspace Ctrl+H Deletecharacterbeforecursorincommandline. Ctrl+K Cutcontents(kill)toendofcommandline. Shift+Home Highlighttobeginningofcommandline. Shift+End Highlighttoendoflastline.CanstartatanylineintheCommandWindow.
相关文章推荐
- mac系统命令行窗口输入javac命令,输出中文乱码得问题
- SecureCRT连接串口时,不能输入控制命令,但能输出打印信息
- mac系统命令行窗口输入javac命令,输出中文乱码得问题
- mac系统命令行窗口输入javac命令,输出中文乱码得问题
- mac系统命令行窗口输入javac命令,输出中文乱码得问题
- 关于linux下printf命令控制输出字…
- 输入/输出 格式的控制_C++
- 5.2输入/输出控制方式
- [学习笔记]Java输入输出和流程控制
- Linux 输入\输出相关命令 echo read tee
- 如何在Win32窗口程序中发命令打开一个控制台,往里面打印(printf())输出一些数据
- C#控制台的输入和输出-Console类-从控制台输入
- doc窗口 输入命令net start mysql 服务名无效
- linux中如何以一个命令的输出作为另外一个命令的输入---用``
- python通过PIPE通讯控制子进程输入命令执行
- 一起学Shell之(六)输入、输出、文件与命令执行 推荐
- Linux命令学习之路---输入输出状态(iostat)命令
- python 变量,数据类型,用户输入输出,流程控制,循环
- Linux--Shell 编程-bash,命令替换,if分支嵌套,运算,输入输出
- uart(4)-输入命令来控制灯亮灭