MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] Matlab的输出语句怎么用? (https://www.labfans.com/bbs/showthread.php?t=11883)

langel 2010-07-21 21:38

Matlab的输出语句怎么用?
 
Matlab的输出语句只有fprintf和disp吗?它们的用法有什么区别?

yhcode 2010-07-23 09:40

回复: Matlab的输出语句怎么用?
 
首先,你要确定你要把待输出的内容输出到哪里,是文件里还是commend window。fprintf是把数据以一定格式输出到一个文件里,disp是将提示字符串或变量值输出到commend window,还可以输出一个超链接。如:
fprintf:
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'wt');%[COLOR="red"]需要先打开一个文件[/COLOR]
fprintf(fid, '%[COLOR="Red"]6.2f %12.8f[/COLOR]\n', y); %
fclose(fid)
disp:
disp(' Corn Oats Hay')
disp(rand(5,3))
结果在命令窗口显示:
Corn Oats Hay
0.2113 0.8474 0.2749
0.0820 0.4524 0.8807
0.7599 0.8075 0.6538
0.0087 0.4832 0.4899
0.8096 0.6135 0.7741
另外:
disp('<a href = "http://www.mathworks.com">The MathWorks Web Site</a>')
显示一个超链接:[U][COLOR="Blue"]The MathWorks Web Site[/COLOR][/U]

rayleighw 2010-08-01 18:48

回复: Matlab的输出语句怎么用?
 
[QUOTE=yhcode;37610]首先,你要确定你要把待输出的内容输出到哪里,是文件里还是commend window。fprintf是把数据以一定格式输出到一个文件里,disp是将提示字符串或变量值输出到commend window,还可以输出一个超链接。如:
fprintf:
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt', 'wt');%[COLOR="red"]需要先打开一个文件[/COLOR]
fprintf(fid, '%[COLOR="Red"]6.2f %12.8f[/COLOR]\n', y); %
fclose(fid)
disp:
disp(' Corn Oats Hay')
disp(rand(5,3))
结果在命令窗口显示:
Corn Oats Hay
0.2113 0.8474 0.2749
0.0820 0.4524 0.8807
0.7599 0.8075 0.6538
0.0087 0.4832 0.4899
0.8096 0.6135 0.7741
另外:
disp('<a href = "http://www.mathworks.com">The MathWorks Web Site</a>')
显示一个超链接:[U][COLOR="Blue"]The MathWorks Web Site[/COLOR][/U][/QUOTE]

那个 text 和他们又有什么区别呢?

huzhe008 2011-01-06 14:08

回复: Matlab的输出语句怎么用?
 
还有:sprintf('....');直接输出在command window中

gunzhusigan 2012-07-14 11:30

回复: Matlab的输出语句怎么用?
 
谢谢你的分享!












SIGNATURE.....................................................................................
[url=http://www.gunzhusigan.com/]昊研精密设备有限公司[/url]|[url]http://www.gunzhusigan.com/[/url]


所有时间均为北京时间。现在的时间是 05:08

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.