声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 769|回复: 4

[综合讨论] 格式化I/O示例的代码问题

[复制链接]
发表于 2008-9-10 14:52 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
function data=txtio_examp
%TXTIO_EXAMP文本文件的格式化输入输出
%打开一个文本文件写入数据
[fid msg]=fopen('square_mat.txt','wt');
if(fid==-1)
     disp(msg);
     return;
end
%写入数据
fprintf(fid,'%s\n','文本文件格式化输入输出示例');
fprintf(fid,'%i\t%i\t%i\n',[1 2 3;4 5 6;7 8 9]);
%关闭文件

问题:
在上面的代码中,fprintf(fid,'%i\t%i\t%i\n',[1 2 3;4 5 6;7 8 9]);这句话是什么意思呢?'%i\t%i\t%i\n'是什么输出啊?%i 和 \t 等这些基础的东西我记不起来了,望大家能提醒一下。
回复
分享到:

使用道具 举报

发表于 2008-9-10 15:19 | 显示全部楼层

回复 楼主 小脉 的帖子

lz,我建议你运行一下
你就知道了
 楼主| 发表于 2008-9-10 15:31 | 显示全部楼层
我也运行了,我就是不懂“%i”是什么输出格式呢?“%i\t”又怎么个输出了? 总是闹糊涂,所以求教于大家了。
发表于 2008-9-10 16:38 | 显示全部楼层
%c Single character

%d Decimal notation (signed)

%e Exponential notation (using a lowercase e as in 3.1415e+00)

%E Exponential notation (using an uppercase E as in 3.1415E+00)

%f Fixed-point notation

%g The more compact of %e or %f, as defined in [2]. Insignificant zeros do not print.

%G Same as %g, but using an uppercase E

%i Decimal notation (signed)

%o Octal notation (unsigned)

%s String of characters

%u Decimal notation (unsigned)

%x Hexadecimal notation (using lowercase letters a–f)

%X Hexadecimal notation (using uppercase letters A–F)


\b Backspace

\f Form feed

\n New line

\r Carriage return

\t Horizontal tab

\\ ackslash

\'' or '' (two single quotes) Single quotation mark

%% Percent character



以上,你只要在matlab帮助里搜索fprintf就知道了

评分

1

查看全部评分

 楼主| 发表于 2008-9-10 17:30 | 显示全部楼层
好的,谢谢你!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-23 03:16 , Processed in 0.055720 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表