- 浏览: 4412310 次
- 性别:
- 来自: 湛江
博客专栏
-
SQLite源码剖析
浏览量:80131
-
WIN32汇编语言学习应用...
浏览量:70350
-
神奇的perl
浏览量:103593
-
lucene等搜索引擎解析...
浏览量:286571
-
深入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常用方法汇总(转载)
text1.txt内容如下:
货币资金,6865234.00 , 短期借款,120000.00
应收票据,72120.00 , 应付票据,85500.00
应收账款,38050.00 , 应付账款,80200.00
减:坏账准备,, 预收账款,
应收账款净额,38050.00 , 应付工资,
其他应收款,, 应付福利费,8430.00
预付账款,26600.00 , 应交税金,24420.00
存 货,281950.00 , 应付股利,34000.00
待摊费用,100.00 , 其他应付款,
流动资产合计,7284054.00 , 预提费用,1600.00
>> help textread
TEXTREAD Read formatted data from text file.
A = TEXTREAD('FILENAME')
A = TEXTREAD('FILENAME','',N)
A = TEXTREAD('FILENAME','',param,value, ...)
A = TEXTREAD('FILENAME','',N,param,value, ...) reads numeric data from
the file FILENAME into a single variable. If the file contains any
text data, an error is produced.
[A,B,C, ...] = TEXTREAD('FILENAME','FORMAT')
[A,B,C, ...] = TEXTREAD('FILENAME','FORMAT',N)
[A,B,C, ...] = TEXTREAD('FILENAME','FORMAT',param,value, ...)
[A,B,C, ...] = TEXTREAD('FILENAME','FORMAT',N,param,value, ...) reads
data from the file FILENAME into the variables A,B,C,etc. The type of
each return argument is given by the FORMAT string. The number of
return arguments must match the number of conversion specifiers in the
FORMAT string. If there are fewer fields in the file than in the
format string, an error is produced. See FORMAT STRINGS below for
more information.
If N is specified, the format string is reused N times. If N is -1 (or
not specified) TEXTREAD reads the entire file.
If param,value pairs are supplied, user configurable options customize
the behavior of TEXTREAD. See USER CONFIGURABLE OPTIONS below.
TEXTREAD works by matching and converting groups of characters from the
file. An input field is defined as a string of non-whitespace
characters extending to the next whitespace or delimiter character
or until the field width is exhausted. Repeated delimiter characters
are significant while repeated whitespace characters are treated as
one.
FORMAT STRINGS
If the FORMAT string is empty, TEXTREAD will only numeric data.
The FORMAT string can contain whitespace characters (which are
ignored), ordinary characters (which are expected to match the next
non-whitespace character in the input), or conversion specifications.
Supported conversion specifications:
%n - read a number - float or integer (returns double array)
%5n reads up to 5 digits or until next delimiter
%d - read a signed integer value (returns double array)
%5d reads up to 5 digits or until next delimiter
%u - read an integer value (returns double array)
%5u reads up to 5 digits or until next delimiter
%f - read a floating point value (returns double array)
%5f reads up to 5 digits or until next delimiter
%s - read a whitespace separated string (returns cellstr)
%5s reads up to 5 characters or until whitespace
%q - read a double-quoted string, ignoring the quotes (returns cellstr)
%5q reads up to 5 non-quote characters or until whitespace
%c - read character or whitespace (returns char array)
%5c reads up to 5 characters including whitespace
%[...] - reads characters matching characters between the
brackets until first non-matching character or
whitespace (returns cellstr)
use %[]...] to include ]
%5[...] reads up to 5 characters
%[^...] - reads characters not matching characters between the
brackets until first matching character or whitespace
(returns cellstr)
use %[^]...] to exclude ]
%5[^...] reads up to 5 characters
Note: Format strings are interpreted as with sprintf before parsing.
For example, textread('mydata.dat','%s\t') will search for a tab not
the character '\' followed by the character 't'. See the Language
Reference Guide or a C manual for complete details.
Using %* instead of % in a conversion causes TEXTREAD to skip the
matching characters in the input (and no output is created for this
conversion).
The % can be followed by an optional field width to handle fixed
width fields. For example %5d reads a 5 digit integer. In
addition the %f format supports the form %<width>.<prec>f.
USER CONFIGURABLE OPTIONS
Possible param/value options are:
'bufsize' - maximum string length in bytes (default is 4095)
'commentstyle' - one of
'matlab' -- characters after % are ignored
'shell' -- characters after # are ignored
'c' -- characters between /* and */ are ignored
'c++' -- characters after // are ignored
'delimiter' - delimiter characters (default is none)
'emptyvalue' - empty cell value in delimited files (default is 0)
'endofline' - end of line character (default determined from file)
'expchars' - exponent characters (default is 'eEdD')
'headerlines' - number of lines at beginning of file to skip
'whitespace' - whitespace characters (default is ' \b\t')
TEXTREAD is useful for reading text files with a known format. Both
fixed and free format files can be handled.
Examples:
Suppose the text file mydata.dat contains data in the following form:
Sally Type1 12.34 45 Yes
Joe Type2 23.54 60 No
Bill Type1 34.90 12 No
Read each column into a variable
[names,types,x,y,answer] = textread('mydata.dat','%s%s%f%d%s');
Read first column into a cell array (skipping rest of line)
[names]=textread('mydata.dat','%s%*[^\n]')
Read first character into char array (skipping rest of line)
[initials]=textread('mydata.dat','%c%*[^\n]')
Read file as a fixed format file while skipping the doubles
[names,types,y,answer] = textread('mydata.dat','%9c%5s%*f%2d%3s');
Read file and match Type literal
[names,typenum,x,y,answer]=textread('mydata.dat','%sType%d%f%d%s');
Read m-file into cell array of strings
file = textread('fft.m','%s','delimiter','\n','whitespace','');
To read all numeric data from a delimited text file, use a single output
argument, empty format string, and the appropriate delimiter. For
example, suppose data.csv contains:
1,2,3,4
5,6,7,8
9,10,11,12
Read the whole matrix into a single variable:
[data] = textread('data.csv','','delimiter',',');
Read the first two columns into two variables:
[col1, col2] = textread('data.csv','%n%n%*[^\n]','delimiter',',');
For files with empty cells, use the emptyvalue parameter. Suppose
data.csv contains:
1,2,3,4,,6
7,8,9,,11,12
Read the file like this, using NaN in empty cells:
[data] = textread('data.csv','','delimiter',',','emptyvalue',NaN);
The TEXTSCAN function is intended as a replacement for both STRREAD and
TEXTREAD.
>> [name1,value1,name2,value2]=textread('e:\test1.txt','%s %f %s %f','delimiter',',')
name1 =
' 货币资金'
' 应收票据'
' 应收账款'
'减:坏账准备'
'应收账款净额'
' 其他应收款'
' 预付账款'
' 存 货'
' 待摊费用'
' 流动资产合计'
value1 =
6865234
72120
38050
0
38050
0
26600
281950
100
7284054
name2 =
' 短期借款'
'应付票据'
' 应付账款'
' 预收账款'
' 应付工资'
' 应付福利费'
' 应交税金'
' 应付股利'
' 其他应付款'
' 预提费用'
value2 =
120000
85500
80200
0
0
8430
24420
34000
0
1600
>>
读取第一行
>> [name1,value1,name2,value2]=textread('e:\test1.txt','%s %f %s %f',1,'delimiter',',')
name1 =
' 货币资金'
value1 =
6865234
name2 =
' 短期借款'
value2 =
120000
>>
前2行
>> [name1,value1,name2,value2]=textread('e:\test1.txt','%s %f %s %f',2,'delimiter',',')
name1 =
' 货币资金'
' 应收票据'
value1 =
6865234
72120
name2 =
' 短期借款'
'应付票据'
value2 =
120000
85500
>>
发表评论
-
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 27301. 谱聚类 给你博客园上若干个博客,让你将它 ... -
对变化建模-用差分方程-动力系统及常数解
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函数可以大致分为基本数学函数、数组和矩阵操作、绘图函数、数据处理与分析、控制流和逻辑函数、文件输入输出、系统接口等几大类。例如,`sin`、`cos`等是基础数学函数,用于三角运算;`zeros`、`ones`生成...
很抱歉,但根据提供的文件信息,“derdikman-Dordek-et-al.-Matlab-code.zip”似乎是一个包含Matlab代码的压缩包,而压缩包内的文件名称列表却是一系列工作总结和计划的文档,这二者之间并没有直接关联。Matlab是一...
在命令窗口中输入命令进行计算,工作空间显示变量及其值,历史窗口记录了之前输入的命令,而文件浏览器则帮助我们管理MATLAB脚本和函数。 二、数据类型与变量 MATLAB支持多种数据类型,包括数值型(如单精度float、...
1. 文本文件读入:使用fscanf函数或textread函数从文本文件中读入数据。 2. 二进制文件读入:使用fread函数从二进制文件中读入数据。 3. 数据库读入:使用database函数从数据库中读入数据。 三、MATLAB中读入数据...
- **变量与数据类型**:MATLAB支持多种数据类型,如标量、向量、矩阵、复数、字符串等。理解这些基本数据结构对于编写有效的MATLAB代码至关重要。 - **运算符与表达式**:MATLAB支持算术、关系、逻辑等多种运算符...
2. **读写文件**:当处理包含非ASCII字符的文件时,需要在`textread`, `textwrite`, 或其他文件操作函数中指定`'-encoding'`选项,如`'-encoding','utf8'`,以确保正确解析和保存Unicode字符。 3. **兼容性**:在跨...
在MATLAB开发中,日志文件的读写是常见的任务,尤其在数据分析、调试和监控等场景中。Roehrig Engineering Shock 5.x是一款专业软件,用于模拟和分析冲击加载情况,它生成的日志文件可能包含了大量的实验数据和计算...
首先,MATLAB提供了一个内置函数`textread`,可以用来读取文本文件的内容。例如,如果你有一个名为`data.txt`的文本文件,你可以用以下代码读取文件的全部内容: ```matlab fid = fopen('data.txt', 'r'); content ...
### MATLAB中读取TXT数据文件的方法 在MATLAB中处理文本数据时,经常会遇到需要从TXT文件中读取数据的情况。这些TXT文件可能只包含数值数据、或者混合了中文字符和数字等多种情况。本文将详细介绍如何根据不同类型...
介绍了Matlab中常用的textread和textscan函数的使用,通过实例演示文件文本的读取
在本节中,我们将详细介绍MATLAB中的输入输出函数,包括文本读取、文件操作、二进制I/O函数和格式化I/O函数等。 文本读取函数 MATLAB提供了多种文本读取函数,以读取文本文件中的数据。其中,textread函数是其中之...
- 读写文件:用load、save、textread、csvwrite等函数处理各种数据格式。 - 数据接口:与Excel、数据库和其他软件交换数据。 8. **类与对象**: -面向对象编程:定义类,创建对象,实现继承和封装。 - 工具箱:...
7. **CST与MATLAB的数据交换**:为了实现两者之间的通信,可能需要编写MATLAB脚本来读取和解析CST的输出文件,或者利用CST提供的专用MATLAB接口,如CST MATLAB Link,它可以简化数据交互过程。 8. **优化流程**:在...
这个场景中提到的"code_matlab_文本文件筛选输出_"是一个与MATLAB相关的项目,目标是根据用户指定的气象站代码,从大型文本文件中筛选出相应气象站的信息并进行输出。MATLAB是一种强大的编程环境,尤其适合数值计算...
`load` 命令用于从文件中加载变量,通常无需指定文件类型即可自动识别。若希望强制使用某种格式加载文件,可以通过 `-ASCII` 或 `-MAT` 参数实现。 #### 2. `fopen` 和 `fclose` `fopen` 命令用于打开文件以便读取...
这个“matlab开发-文件夹目录列表”可能是一个示例或教程,旨在教授如何使用MATLAB获取指定文件夹下的所有文件和子文件夹的列表。下面我们将详细探讨这一主题。 首先,MATLAB中的`dir`函数是用于获取目录信息的关键...
在提供的文件"Matlab 中实现哈夫曼编译码.doc"中,详细描述了如何在Matlab环境下实现这些步骤。它可能包括了具体的代码示例,解释了如何用Matlab的语法来处理频率表、构建哈夫曼树、生成和解码编码等。通过学习这份...
Using file io functions in Matlab is a bit of confusion due to the variety and the issue of vectorisation. In the following snippet data is read back using: fscanf : creates a vector row by row ...