- 浏览: 4412371 次
- 性别:
- 来自: 湛江
博客专栏
-
SQLite源码剖析
浏览量:80133
-
WIN32汇编语言学习应用...
浏览量:70351
-
神奇的perl
浏览量:103594
-
lucene等搜索引擎解析...
浏览量:286574
-
深入lucene3.5源码...
浏览量:15054
-
VB.NET并行与分布式编...
浏览量:67786
-
silverlight 5...
浏览量:32292
-
算法下午茶系列
浏览量:46075
文章分类
最新评论
-
yoyo837:
counters15 写道目前只支持IE吗?插件的东西是跨浏览 ...
Silverlight 5 轻松开启绚丽的网页3D世界 -
shuiyunbing:
直接在前台导出方式:excel中的单元格样式怎么处理,比如某行 ...
Flex导出Excel -
di1984HIT:
写的很好~
lucene入门-索引网页 -
rjguanwen:
在win7 64位操作系统下,pygtk的Entry无法输入怎 ...
pygtk-entry -
ldl_xz:
http://www.9958.pw/post/php_exc ...
PHPExcel常用方法汇总(转载)
help fseek
FSEEK Set file position indicator.
STATUS = FSEEK(FID, OFFSET, ORIGIN) repositions the file position
indicator in the file associated with the given FID. FSEEK sets the
position indicator to the byte with the specified OFFSET relative to
ORIGIN.
FID is an integer file identifier obtained from FOPEN.
OFFSET values are interpreted as follows:
>= 0 Move position indicator OFFSET bytes after ORIGIN.
< 0 Move position indicator OFFSET bytes before ORIGIN.
ORIGIN values are interpreted as follows:
'bof' or -1 Beginning of file
'cof' or 0 Current position in file
'eof' or 1 End of file
STATUS is 0 on success and -1 on failure. If an error occurs, use
FERROR to get more information.
Example:
fseek(fid,0,-1)
"rewinds" the file.
fseek用于定位
1)读
>> fid=fopen('test.m','r')
fid =
3
>> fseek(fid,5,'bof')
ans =
0
>> a=fread(fid,5,'uint8=>char')
a =
1
0
;
>>
>> fseek(fid,0,'bof')
ans =
0
>> a=fread(fid,5,'uint8=>char')
a =
P
=
[
1
>>
2)写
>> fid=fopen('test.m','r+')
fid =
3
>> fseek(fid,0,'eof')
ans =
0
>> fwrite(fid,'%增加一行','char')
ans =
5
>> fclose(fid)
ans =
0
>>
定位于当前位置写,注意这种写是改写
>> fid=fopen('test.m','r+')
fid =
3
>> fseek(fid,0,'cof')
ans =
0
>> ftell(fid)
ans =
0
>> fwrite(fid,'%增加上面一行','char')
ans =
7
>> fclose(fid)
ans =
0
>>
ftell得到当前位置
help ftell
FTELL Get file position indicator.
POSITION = FTELL(FID) returns the location of the file position
indicator in the specified file. Position is indicated in bytes
from the beginning of the file. If -1 is returned, it indicates
that the query was unsuccessful. Use FERROR to determine the nature
of the error.
FID is an integer file identifier obtained from FOPEN.
3、读取行
1)fgetl
>> fid=fopen('test.m','r')
fid =
4
>> mline=fgetl(fid)
mline =
%增加上面一行 1];
>> mline=fgetl(fid)
mline =
T=[0 1 0];
>> mline=fgetl(fid)
mline =
w=[0 0 ];
>> mline=fgetl(fid)
mline =
[S,Q]=size(T)
>> mline=fgetl(fid)
mline =
b=0;
>>
2)fgets
与fgetl的区别就是,fgets是保留换行符读取一行
>> mline=fgets(fid)
mline =
A=purelin(w*P+b);
>>
4、格式化读写ascii
1)读
>> a=fscanf(fid,'%s',10)
a =
e=T-A;LP.lr=maxlinlr(P)%误差平方和sse=sumsqr(e);whilesse>0.0000001dW=learnwh([],P,[],[],[],[],e,[],[],[],LP,[]);dB=learnwh(b,ones(1,Q),[],[],[],[],e,[],[],[],LP,[]);
>>
>> a=fscanf(fid,'%s')
a =
w=w+dW;b=b+dB;A=purelin(w*P+b)e=T-Asse=sumsqr(e)end%增加一行
>>
help fscanf
FSCANF Read formatted data from file.
[A,COUNT] = FSCANF(FID,FORMAT,SIZE) reads data from the file specified
by file identifier FID, converts it according to the specified FORMAT
string, and returns it in matrix A. COUNT is an optional output
argument that returns the number of elements successfully read.
FID is an integer file identifier obtained from FOPEN.
SIZE is optional; it puts a limit on the number of elements that
can be read from the file; if not specified, the entire file
is considered; if specified, valid entries are:
N read at most N elements into a column vector.
inf read at most to the end of the file.
[M,N] read at most M * N elements filling at least an
M-by-N matrix, in column order. N can be inf, but not M.
If the matrix A results from using character conversions only and
SIZE is not of the form [M,N] then a row vector is returned.
FORMAT is a string containing ordinary characters and/or C language
conversion specifications. Conversion specifications involve the
character %, optional assignment-suppressing asterisk and width
field, and conversion characters d, i, o, u, x, e, f, g, s, c, and
[. . .] (scanset). Complete ANSI C support for these conversion
characters is provided consistent with 'expected' MATLAB behavior.
For a complete conversion character specification, see the Language
Reference Guide or a C manual.
If %s is used an element read may cause several MATLAB matrix
elements to be used, each holding one character. Use %c to read
space characters; the format %s skips all white space.
MATLAB reads characters using the encoding scheme associated with
the file. See FOPEN for more information. If the format string
contains ordinary characters, MATLAB matches each of those characters
with a character read from the file after converting both to the
MATLAB internal representation of characters.
Mixing character and numeric conversion specifications causes the
resulting matrix to be numeric and any characters read to show up
as their numeric values, one character per MATLAB matrix element.
FSCANF differs from its C language namesake in an important respect -
it is "vectorized" in order to return a matrix argument. The format
string is recycled through the file until an end-of-file is reached
or the amount of data specified by SIZE is read in.
Examples:
S = fscanf(fid,'%s') reads (and returns) a character string.
A = fscanf(fid,'%5d') reads 5-digit decimal integers.
2)写
>> fid=fopen('test.m','r+')
fid =
4
>> fseek(fid,0,'eof')
ans =
0
>> x=[123,3452]
x =
123 3452
>> fprintf(fid,'%d %6.2f',x)
ans =
11
>> fclose(fid)
ans =
0
>>
help fprintf
FPRINTF Write formatted data to text file.
FPRINTF(FID, FORMAT, A, ...) applies the FORMAT to all elements of
array A and any additional array arguments in column order, and writes
the data to a text file. FID is an integer file identifier. Obtain
FID from FOPEN, or set it to 1 (for standard output, the screen) or 2
(standard error). FPRINTF uses the encoding scheme specified in the
call to FOPEN.
FPRINTF(FORMAT, A, ...) formats data and displays the results on the
screen.
COUNT = FPRINTF(...) returns the number of bytes that FPRINTF writes.
FORMAT is a string that describes the format of the output fields, and
can include combinations of the following:
* Conversion specifications, which include a % character, a
conversion character (such as d, i, o, u, x, f, e, g, c, or s),
and optional flags, width, and precision fields. For more
details, type "doc fprintf" at the command prompt.
* Literal text to print.
* Escape characacters, including:
\b Backspace '' Single quotation mark
\f Form feed %% Percent character
\n New line \\ Backslash
\r Carriage return \xN Hexadecimal number N
\t Horizontal tab \N Octal number N
For most cases, \n is sufficient for a single line break.
However, if you are creating a file for use with Microsoft
Notepad, specify a combination of \r\n to move to a new line.
Notes:
If you apply an integer or string conversion to a numeric value that
contains a fraction, MATLAB overrides the specified conversion, and
uses %e.
Numeric conversions print only the real component of complex numbers.
Example: Create a text file called exp.txt containing a short table of
the exponential function.
x = 0:.1:1;
y = [x; exp(x)];
fid = fopen('exp.txt','w');
fprintf(fid,'%6.2f %12.8f\n',y);
fclose(fid);
Examine the contents of exp.txt:
type exp.txt
MATLAB returns:
0.00 1.00000000
0.10 1.10517092
...
1.00 2.71828183
最后是关闭文件
help fclose
FCLOSE Close file.
ST = FCLOSE(FID) closes the file associated with file identifier FID,
which is an integer value obtained from an earlier call to FOPEN.
FCLOSE returns 0 if successful or -1 if not. If FID does not represent
an open file, or if it is equal to 0 (standard input), 1 (standard
output), or 2 (standard error), FCLOSE throws an error.
ST = FCLOSE('all') closes all open files, except 0, 1 and 2.
See also fopen, fclose, fscanf, fread, fwrite, sprintf, disp.
发表评论
-
R语言与数据分析
2015-05-15 20:58 2161当今计算机系统要处理的数据类型变得多种多样,并且为了深入理 ... -
机器学习实践指南:案例应用解析
2014-04-17 19:53 1005试读及购买链接 《机器 ... -
matlab-矩阵合并
2013-06-10 13:56 3230a = 1 2 3 2 -
人工智能与数据分析所需要的知识
2013-04-30 18:27 292想较好得在数据分析和人工智能相关领域发展,最好具备以下基础: ... -
麦哈普的AI乐园【myhaspl@qq.com】我的另一个博客(机器学习、数据分析、智能计算的原创)
2013-04-28 10:52 11http://blog.csdn.net/u0102556 ... -
R-并行计算
2013-04-28 10:50 6126啊。。。找了一下,R 居然真的有办法可以多cpu平行运算!! ... -
谱聚类
2013-04-11 10:44 27311. 谱聚类 给你博客园上若干个博客,让你将它 ... -
对变化建模-用差分方程-动力系统及常数解
2013-04-09 15:24 1385差分表示在一个时间周期里考察对象的变化量。 差分表示在一个时 ... -
逻辑斯蒂映射-伪随机数
2013-04-04 15:28 3310逻辑斯蒂映射的形式为 x_(n+1)=ax_n( ... -
matlab-多项式乘除法及式子和导数
2013-03-21 15:06 4704>> a=[22 12 4 54] ... -
matlab-数组-元胞数据与结构数组
2013-03-20 17:45 3296y、z是元胞数组,num2cell完成由数值数组到元胞数组的 ... -
矩阵-范数
2013-03-13 17:30 1926>> a a = 12 33 ... -
向量-范数
2013-03-13 16:06 2374>> b=a(3,:) b = 22 ... -
矩阵-求逆
2013-02-27 15:51 2525设R是一个交换环,A是 ... -
lisp-猜数字算法与全局函数、变量
2013-01-30 17:55 1608* (defvar *big* 100) *BIG* ... -
开源 Lisp 相关项目
2013-01-19 22:38 3931IOLib 项目 (http://common-lisp.n ... -
四分位数求法
2012-11-22 20:18 2793四分位数间距:是上四分位数与下四分位数之差,用四分位数间距可反 ... -
matlab-神经网络-自定义多层感知器解决异或(2)
2012-10-10 22:33 2509继续定义单元神经元 net.inputs{i}.ran ... -
matlab-神经网络-自定义多层感知器解决异或(1)
2012-10-09 22:41 5251>> net=network net = ... -
matlab-模态对话框
2012-10-05 16:59 3537modal dialog box with the comm ...
相关推荐
在MATLAB中,文件的读写是编程过程中常见的任务,主要涉及处理文本文件和二进制文件。以下是对MATLAB中几种主要文件读写函数的详细解析: 1. **textread**: `textread`函数是用于读取文本文件的便捷工具。它能...
`fread`用于读取二进制文件,而`fscanf`则适用于格式化的文本文件。在例子中,`fscanf(fid, '%f')`会尝试读取文件中的浮点数。 在处理文本文件时,`fscanf`非常灵活,可以按照指定的格式读取数据。例如,`fscanf...
在MATLAB编程环境中,STL(STereoLithography)文件是一种常见的3D模型格式,广泛用于3D打印和计算机图形学。`stlWriteBinaryOrAsciiSTLFile`函数是用来将MATLAB中的3D网格数据写入STL文件,支持二进制和ASCII两种...
- **`fscanf` 和 `fprintf`**:用于读写文本文件,格式控制严格。 - **`fgetl` 和 `fgets`**:按行读取文本文件,适用于格式未知的情况。 **示例:** ```matlab fid = fopen('example.txt', 'r'); line = fgetl(fid...
`%f`、`%s`是格式化字符串,分别对应浮点数和字符串类型的数据。`num`、`txt`和`raw`分别存储了读取到的数据。 此外,MATLAB的`csvread`函数适用于CSV格式的TXT文件,它可以自动将数据解析为矩阵: ```matlab data...
MATLAB还提供了其他文件操作函数,如`fopen/fclose`用于打开和关闭文件,`fread/fwrite`处理二进制数据,`fscanf/fprintf`用于格式化的文本数据读写,`fgetl/fgets`用于读取文件行,以及`ferror/feof/fseek/ftell`...
Matlab作为强大的数值计算和数据可视化环境,提供了处理这种格式图像的功能。本文将详细探讨如何在Matlab中读取和写入PBM、PGM和PPM图片,并介绍相关的编程知识。 首先,PBM(Portable Bitmap)用于黑白图像,PGM...
- `fprintf`与`fscanf`:格式化写入和读取数据,前者用于将数据按照指定格式写入文件,后者用于按格式从文件读取数据。 - `textscan`与`textwrite`:用于处理非结构化文本数据的读写。 - `load`与`save`:导入和...
matlab 文件读写程序的汇总 Matlab 文件读写是 Matlab 编程中非常重要的一部分,包括读取文件和写入文件。下面将对 Matlab 中的四种文件读写方式进行汇总。 1. textread 函数 textread 函数是 Matlab 中最常用的...
在MATLAB中,将数据输出并保存为TXT格式文件是一项常见的任务,这有助于在不同的软件或平台之间交换数据。以下是一些关于如何在MATLAB中实现这一操作的详细步骤和相关知识点。 首先,我们需要理解MATLAB中的数据...
除了上述高级命令外,Matlab还提供了一系列低级文件I/O函数,如`fopen`、`fclose`、`fprintf`、`fscanf`等,这些函数提供了更多的灵活性,允许用户自定义数据的读写格式。 ##### fopen与fclose - **fopen**: 打开...
`fprintf`类似于C语言的printf,允许格式化输出,而`save`或`.savetxt`则将工作空间的变量保存为ASCII格式。 3. **二进制数据的处理** - **读取二进制数据**:使用`fread`函数读取二进制数据,它接受文件标识和要...
- **fprintf**:格式化输出到打开的文件,可以将数据写入到指定的文件中。 - **fclose**:关闭已打开的文件,确保数据完整写入。 3. **导出单个.coe文件**: 以下是一个简单的Matlab脚本示例,用于生成一个包含...
- MATLAB的格式化选项:包括short、long、short e、long e、bank等格式化方式。 9. MATLAB矩阵和向量运算: - 矩阵运算与向量运算的区别和使用。 - 矩阵的点运算(element-wise operations)与矩阵运算(matrix ...
通过这些基本的文件读写指令,我们可以方便地在 MATLAB 中处理各种类型的数据,这对于数据分析、模型建立和结果可视化等工作至关重要。了解并熟练掌握这些指令,将极大地提升 MATLAB 编程的效率和实用性。
综上所述,MATLAB 的 `inifile` 功能为处理 ASCII 格式的 INI 文件提供了便利,其高效、灵活的特点使其成为管理配置数据的理想选择。开发者可以通过学习和熟练掌握 `inifile`,提高代码的可维护性和用户体验。
STL(STereo Lithography)格式是3D打印和计算机辅助设计(CAD)领域中广泛使用的文件格式,它主要用于存储三维几何数据。MATLAB是一款强大的数值计算和数据分析软件,但默认并不支持直接读取STL文件。为了在MATLAB...
默认加载的也是MATLAB二进制格式的文件,加载的文件名可以省略,MATLAB会尝试加载与当前脚本同名的`.mat`文件。 4. **文件存取管理** - `fopen`函数:用于打开文件,返回一个文件标识符(FID)。基本语法有: - `...
这个格式是便携式的,支持ASCII和二进制两种模式,具有较好的读写效率。 PLY文件格式由斯坦福大学开发,最初用于他们的“Stanford 3D Scanning Repository”。这种格式包含了顶点、面和其他属性(如颜色、纹理坐标...
需要注意的是,STL文件可以是二进制或ASCII格式,二进制格式更紧凑,读写速度更快,但不如ASCII格式易于阅读。 在MATLAB中,使用surf2stl函数可能如下: ```matlab % 假设已有的表面数据 [x, y] = meshgrid...