- •Is the same as the previous syntax, but accepts attribute value pairs,
- •Xlsfinfo Determine if file contains Microsoft Excel spreadsheet.
- •Internet resource
- •Is a string. Message is either a string or a cell array. If it is a
- •Variables and the Windows registry.
- •Zip file access
- •Individual file can be specified relative to the current directory or
- •Tar file access
- •Individual file can be specified relative to the current directory or
- •Gzip file access
- •Individual file can be specified relative to the current directory or
- •Formatted file I/o
- •Icinterface/fgets
- •If %s is used an element read may cause several matlab matrix
- •Integer NaN as zero.
- •If true, textscan treats
- •File opening and closing
- •It on the matlab search path. On unix systems, filename may also start
- •Binary file I/o
- •If the most recent I/o operation was successful, message is empty
- •Indicator in the specified file. Position is indicated in bytes
- •Memory-mapped file support
- •Is correct for platform it's executed on.
- •Is also a valid partial pathname.
- •Serial port support
- •Instrfind will not find an object with a Name property value of
- •Instrfind will not find an object with a Name property value of
- •Timer support
- •Visible timer objects whose property names and property values match
- •Command window I/o
- •In the current directory. The folder contains an m-file for each web service
matlab\iofun – Функции ввода и вывода файлов
File import/export functions
<dlmread> - Read ASCII delimited file.
DLMREAD Read ASCII delimited file.
RESULT = DLMREAD(FILENAME) reads numeric data from the ASCII
delimited file FILENAME. The delimiter is inferred from the formatting
of the file.
RESULT = DLMREAD(FILENAME,DELIMITER) reads numeric data from the ASCII
delimited file FILENAME using the delimiter DELIMITER. The result is
returned in RESULT. Use '\t' to specify a tab.
When a delimiter is inferred from the formatting of the file,
consecutive whitespaces are treated as a single delimiter. By
contrast, if a delimiter is specified by the DELIMITER input, any
repeated delimiter character is treated as a separate delimiter.
RESULT = DLMREAD(FILENAME,DELIMITER,R,C) reads data from the
DELIMITER-delimited file FILENAME. R and C specify the row R and column
C where the upper-left corner of the data lies in the file. R and C are
zero-based so that R=0 and C=0 specifies the first value in the file.
All data in the input file must be numeric. DLMREAD does not operate
on files containing nonnumeric data, even if the specified rows and
columns for the read contain numeric data only.
RESULT = DLMREAD(FILENAME,DELIMITER,RANGE) reads the range specified
by RANGE = [R1 C1 R2 C2] where (R1,C1) is the upper-left corner of
the data to be read and (R2,C2) is the lower-right corner. RANGE
can also be specified using spreadsheet notation as in RANGE = 'A1..B7'.
DLMREAD fills empty delimited fields with zero. Data files where
the lines end with a non-whitespace delimiter will produce a result with
an extra last column filled with zeros.
See also dlmwrite, csvread, textscan, load, fileformats.
Reference page in Help browser
doc dlmread
<dlmwrite> - Write ASCII delimited file.
DLMWRITE Write ASCII delimited file.
DLMWRITE('FILENAME',M) writes matrix M into FILENAME using ',' as the
delimiter to separate matrix elements.
DLMWRITE('FILENAME',M,'DLM') writes matrix M into FILENAME using the
character DLM as the delimiter.
DLMWRITE('FILENAME',M,'DLM',R,C) writes matrix M starting at
offset row R, and offset column C in the file. R and C are zero-based,
so that R=C=0 specifies the first value in the file.
DLMWRITE('FILENAME',M,'ATTRIBUTE1','VALUE1','ATTRIBUTE2','VALUE2'...)
An alternative calling syntax that uses attribute value pairs for
specifying optional arguments to DLMWRITE. The order of the
attribute-value pairs does not matter, as long as an appropriate value
follows each attribute tag.
DLMWRITE('FILENAME',M,'-append') appends the matrix to the file.
without the flag, DLMWRITE overwrites any existing file.
DLMWRITE('FILENAME',M,'-append','ATTRIBUTE1','VALUE1',...)
Is the same as the previous syntax, but accepts attribute value pairs,
as well as the '-append' flag. The flag can be placed in the argument
list anywhere between attribute value pairs, but not between an
attribute and its value.
USER CONFIGURABLE OPTIONS
ATTRIBUTE : a quoted string defining an Attribute tag. The following
attribute tags are valid -
'delimiter' => Delimiter string to be used in separating matrix
elements.
'newline' => 'pc' Use CR/LF as line terminator
'unix' Use LF as line terminator
'roffset' => Zero-based offset, in rows, from the top of the
destination file to where the data it to be
written.
'coffset' => Zero-based offset, in columns, from the left side
of the destination file to where the data is to be
written.
'precision' => Numeric precision to use in writing data to the
file, as significant digits or a C-style format
string, starting with '%', such as '%10.5f'. Note
that this uses the operating system standard
library to truncate the number.
EXAMPLES:
DLMWRITE('abc.dat',M,'delimiter',';','roffset',5,'coffset',6,...
'precision',4) writes matrix M to row offset 5, column offset 6, in
file abc.dat using ; as the delimiter between matrix elements. The
numeric precision is of the data is set to 4 significant decimal
digits.
DLMWRITE('example.dat',M,'-append') appends matrix M to the end of
the file example.dat. By default append mode is off, i.e. DLMWRITE
overwrites the existing file.
DLMWRITE('data.dat',M,'delimiter','\t','precision',6) writes M to file
'data.dat' with elements delimited by the tab character, using a precision
of 6 significant digits.
DLMWRITE('file.txt',M,'delimiter','\t','precision','%.6f') writes M
to file file.txt with elements delimited by the tab character, using a
precision of 6 decimal places.
DLMWRITE('example2.dat',M,'newline','pc') writes M to file
example2.dat, using the conventional line terminator for the PC
platform.
See also dlmread, csvwrite, num2str, sprintf.
Reference page in Help browser
doc dlmwrite
<csvread> - Read a comma separated value file.
CSVREAD Read a comma separated value file.
M = CSVREAD('FILENAME') reads a comma separated value formatted file
FILENAME. The result is returned in M. The file can only contain
numeric values.
M = CSVREAD('FILENAME',R,C) reads data from the comma separated value
formatted file starting at row R and column C. R and C are zero-
based so that R=0 and C=0 specifies the first value in the file.
M = CSVREAD('FILENAME',R,C,RNG) reads only the range specified
by RNG = [R1 C1 R2 C2] where (R1,C1) is the upper-left corner of
the data to be read and (R2,C2) is the lower-right corner. RNG
can also be specified using spreadsheet notation as in RNG = 'A1..B7'.
CSVREAD fills empty delimited fields with zero. Data files where
the lines end with a comma will produce a result with an extra last
column filled with zeros.
See also csvwrite, dlmread, dlmwrite, load, fileformats, textscan.
Reference page in Help browser
doc csvread
<csvwrite> - Write a comma separated value file.
CSVWRITE Write a comma separated value file.
CSVWRITE(FILENAME,M) writes matrix M into FILENAME as
comma separated values.
CSVWRITE(FILENAME,M,R,C) writes matrix M starting at offset
row R, and column C in the file. R and C are zero-based,
that is R=C=0 specifies first number in the file.
See also csvread, dlmread, dlmwrite.
Reference page in Help browser
doc csvwrite
<importdata> - Load data from a file into MATLAB.
IMPORTDATA Load data from file.
IMPORTDATA(FILENAME) loads data from FILENAME into the workspace.
A = IMPORTDATA(FILENAME) loads data into A.
IMPORTDATA(FILENAME, DELIM) interprets DELIM as the column separator in
ASCII file FILENAME. DELIM must be a string. Use '\t' for tab.
IMPORTDATA(FILENAME, DELIM, NHEADERLINES) loads data from ASCII file
FILENAME, reading numeric data starting from line NHEADERLINES+1.
[A DELIM] = IMPORTDATA(...) returns the detected delimiter character
for the input ASCII file.
[A DELIM NHEADERLINES] = IMPORTDATA(...) returns the detected number of
header lines in the input ASCII file.
[...] = IMPORTDATA('-pastespecial', ...) loads data from the system
clipboard rather than from a file.
Notes:
If IMPORTDATA recognizes the file extension, it calls the MATLAB helper
function designed to import the associated file format. Otherwise,
IMPORTDATA interprets the file as a delimited ASCII file.
When the helper function returns more than one nonempty output,
IMPORTDATA combines the outputs into a structure array. For details,
type "doc importdata" at the command prompt.
For ASCII files and spreadsheets, IMPORTDATA expects to find numeric
data in a rectangular form (that is, like a matrix). Text headers can
appear above or to the left of numeric data. To import ASCII files
with numeric characters anywhere else, including columns of character
data or formatted dates or times, use TEXTSCAN instead of IMPORTDATA.
When importing spreadsheets with columns of nonnumeric data, IMPORTDATA
cannot always correctly interpret the column and row headers.
Examples:
1) Import and display an image:
nebula_im = importdata('ngc6543a.jpg');
image(nebula_im);
2) Using a text editor, create an ASCII file called myfile.txt:
Day1 Day2 Day3 Day4 Day5 Day6 Day7
95.01 76.21 61.54 40.57 5.79 20.28 1.53
23.11 45.65 79.19 93.55 35.29 19.87 74.68
60.68 1.85 92.18 91.69 81.32 60.38 44.51
48.60 82.14 73.82 41.03 0.99 27.22 93.18
89.13 44.47 17.63 89.36 13.89 19.88 46.60
Import the file, and view columns 3 and 5:
M = importdata('myfile.txt', ' ', 1);
for k = [3, 5]
disp(M.colheaders{1, k})
disp(M.data(:, k))
disp(' ')
end
See also load, fileformats, textscan, open, load, uiimport.
Reference page in Help browser
doc importdata
<daqread> - Read Data Acquisition Toolbox (.daq) data file.
DAQREAD Read Data Acquisition Toolbox (.daq) data file.
DATA = DAQREAD('FILENAME') reads the data acquisition file, FILENAME,
and returns a M-by-N data matrix, DATA, where M specifies the number
of samples and N specifies the number of channels. If data from
multiple triggers is read, the data from each trigger is separated by
a NaN.
[DATA, TIME] = DAQREAD('FILENAME') reads the data acquisition file,
FILENAME, and returns the time-value pairs. TIME is a vector, the
same length of DATA indicating the relative time of each data sample
relative to the first trigger.
[DATA, TIME, ABSTIME] = DAQREAD('FILENAME') returns the absolute time, ABSTIME, of the first trigger. ABSTIME is returned as a CLOCK vector.
[DATA, TIME, ABSTIME, EVENTS] = DAQREAD('FILENAME') returns a
structure, EVENTS, which contains a log of events.
[DATA,...] = DAQREAD('FILENAME', 'P1', V1, 'P2', V2,...) specifies the
amount of data to be read from the file, FILENAME, the format of the
DATA matrix, the format of the TIME matrix, and whether to return a
time series collection object.
Valid Property Names (P1, P2,...) and Property Values (V1, V2,...)
include:
Samples - [sample range]
Time - [time range in seconds]
Triggers - [trigger range]
Channels - [channel indices or cell array of ChannelNames]
DataFormat - [ {double} | native ]
TimeFormat - [ {vector} | matrix ]
OutputFormat - [ {matrix} | tscollection ]
The Samples, Time and Triggers properties are mutually exclusive,
i.e. either Samples, Triggers or Time can be defined at once.
The TimeFormat and OutputFormat properties are mutually exclusive,
i.e. either TimeFormat or OutputFormat can be defined at once.
The default values for the DataFormat, TimeFormat, and OutputFormat
properties are indicated by braces {}.
Setting the OutputFormat property to 'tscollection' causes DAQREAD
to return a time series collection object. In this case, only the
DATA left hand argument is used.
If DAQREAD returns a time series collection object, DATA will contain
an absolute time series object for each channel in the file, with time=0
set to InitialTriggerTime property of the file. Each time series object is
given a name corresponding to the Name property of the channel. If
this name cannot be used as a time series object name, the name will
be set to 'Channel' with the HwChannel property of the channel
appended. If the DataFormat property is set to 'double', each time
series object in the collection will have the Units field of its
DataInfo property set to the Units property of the corresponding
channel in the file. If the DataFormat property is set to 'native', the
Units property is set to 'native'. In addition, each time series
object will have tsdata.event objects attached corresponding to the
log of events associated with the file. If DAQREAD returns data from
multiple triggers, the data from each trigger is separated by a NaN in
the time series data. This will increase the length of data and time
vectors in the time series object by the number of triggers.
DAQINFO = DAQREAD('FILENAME', 'info') reads the data acquisition file,
FILENAME, and returns a structure, DAQINFO, which contains the
information:
DAQINFO.ObjInfo - a structure containing PV pairs for the data
acquisition object used to create the file,
FILENAME. Note: The UserData property value is
not restored.
DAQINFO.HwInfo - a structure containing hardware information.
The DAQINFO structure can also be obtained with the following syntax:
[DATA, TIME, ABSTIME, EVENTS, DAQINFO] = DAQREAD('FILENAME')
Data Acquisition Toolbox (.daq) data files are created by specifying
a value for the LogFileName property and setting the LoggingMode
property to 'Disk' or 'Disk&Memory'.
Examples:
To read all the data from the file, data.daq:
[data, time] = daqread('data.daq');
To read all the data from the file, data.daq, and return it as a
time series collection object:
data = daqread('data.daq','OutputFormat','tscollection');
To read only samples 1000 to 2000 of channel indices 2, 4 and 7 in
native format from the file, data.daq:
data = daqread('data.daq', 'Samples', [1000 2000],...
'Channels', [2 4 7], 'DataFormat', 'native');
To read only the data which represents the first and second triggers on
all channels from the file, data.daq:
[data, time] = daqread('data.daq', 'Triggers', [1 2]);
To obtain the property values of the channels from the file, data.daq:
daqinfo = daqread('data.daq', 'info');
chaninfo = daqinfo.ObjInfo.Channel;
See also daqhelp, getdata, timeseries, tscollection.
Reference page in Help browser
doc daqread
<matfinfo> - Text description of MAT-file contents.
MATFINFO Text description of MAT-file contents.
See also finfo.
<fileread> - Return contents of file as string vector.
FILEREAD Return contents of file as string vector.
TEXT = FILEREAD('FILENAME') returns the contents of the file FILENAME as a
MATLAB string.
See also fread, textscan, load, web.
Reference page in Help browser
doc fileread
Spreadsheet support
<xlsread> - Get data and text from a spreadsheet in an Excel workbook.
XLSREAD Get data and text from a spreadsheet in an Excel workbook.
[NUMERIC,TXT,RAW]=XLSREAD(FILE) reads the data specified in the Excel
file, FILE. The numeric cells in FILE are returned in NUMERIC, the text
cells in FILE are returned in TXT, while the raw, unprocessed cell
content is returned in RAW.
[NUMERIC,TXT,RAW]=XLSREAD(FILE,SHEET,RANGE) reads the data specified
in RANGE from the worksheet SHEET, in the Excel file specified in FILE.
It is possible to select the range of data interactively (see Examples
below). Please note that the full functionality of XLSREAD depends on
the ability to start Excel as a COM server from MATLAB.
[NUMERIC,TXT,RAW]=XLSREAD(FILE,SHEET,RANGE,'basic') reads an XLS file as
above, using basic input mode. This is the mode used on UNIX platforms
as well as on Windows when Excel is not available as a COM server.
In this mode, XLSREAD does not use Excel as a COM server, which limits
import ability. Without Excel as a COM server, RANGE will be ignored
and, consequently, the whole active range of a sheet will be imported.
Also, in basic mode, SHEET is case-sensitive and must be a string.
[NUMERIC,TXT,RAW]=XLSREAD(FILE,SHEET,RANGE,'',CUSTOMFUN)
[NUMERIC,TXT,RAW,CUSTOMOUTPUT]=XLSREAD(FILE,SHEET,RANGE,'',CUSTOMFUN)
When the Excel COM server is used, allows passing in a handle to a
custom function. This function will be called just before retrieving
the actual data from Excel. It must take an Excel Range object (e.g. of
type 'Interface.Microsoft_Excel_5.0_Object_Library.Range') as input,
and return one as output. Optionally, this custom function may return
a second output argument, which will be returned from XLSREAD as the
fourth output argument, CUSTOMOUTPUT. For details of what is possible
using the EXCEL COM interface, please refer to Microsoft documentation.
INPUT PARAMETERS:
FILE: string defining the file to read from. Default directory is pwd.
Default extension is 'xls'.
SHEET: string defining worksheet name in workbook FILE.
double scalar defining worksheet index in workbook FILE. See
NOTE 1.
RANGE: string defining the data range in a worksheet. See NOTE 2.
MODE: string enforcing basic import mode. Valid value = 'basic'. This
is the mode always used when COM is not available (e.g. on Unix).
RETURN PARAMETERS:
NUMERIC = n x m array of type double.
TXT = r x s cell string array containing text cells in RANGE.
RAW = v x w cell array containing unprocessed numeric and text data.
Both NUMERIC and TXT are subsets of RAW.
EXAMPLES:
1. Default operation:
NUMERIC = xlsread(FILE);
[NUMERIC,TXT]=xlsread(FILE);
[NUMERIC,TXT,RAW]=xlsread(FILE);
2. Get data from the default region:
NUMERIC = xlsread('c:\matlab\work\myspreadsheet')
3. Get data from the used area in a sheet other than the first sheet:
NUMERIC = xlsread('c:\matlab\work\myspreadsheet','sheet2')
4. Get data from a named sheet:
NUMERIC = xlsread('c:\matlab\work\myspreadsheet','NBData')
5. Get data from a specified region in a sheet other than the first
sheet:
NUMERIC = xlsread('c:\matlab\work\myspreadsheet','sheet2','a2:j5')
6. Get data from a specified region in a named sheet:
NUMERIC = xlsread('c:\matlab\work\myspreadsheet','NBData','a2:j5')
7. Get data from a region in a sheet specified by index:
NUMERIC = xlsread('c:\matlab\work\myspreadsheet',2,'a2:j5')
8. Interactive region selection:
NUMERIC = xlsread('c:\matlab\work\myspreadsheet',-1);
You have to select the active region and the active sheet in the
EXCEL window that will come into focus. Click OK in the Data
Selection Dialog when you have finished selecting the active region.
9. Using the custom function:
[NUMERIC,TXT,RAW,CUSTOMOUTPUT] = xlsread('equity.xls', ..., @MyCustomFun)
Where the CustomFun is defined as:
function [DataRange, customOutput] = MyCustomFun(DataRange)
DataRange.NumberFormat = 'Date';
customOutput = 'Anything I want';
This will convert to dates all cells where that is possible.
NOTE 1: The first worksheet of the workbook is the default sheet. If
SHEET is -1, Excel comes to the foreground to enable interactive
selection (optional). In interactive mode, a dialogue will prompt
you to click the OK button in that dialogue to continue in MATLAB.
(Only supported when Excel COM server is available.)
NOTE 2: The regular form is: 'D2:F3' to select rectangular region D2:F3
in a worksheet. RANGE is not case sensitive and uses Excel A1
notation (see Excel Help). (Only supported when Excel COM server
is available.)
NOTE 3: Excel formats other than the default can also be read.
(Only supported when Excel COM server is available.)
See also xlswrite, dlmread, csvread, textscan.
Reference page in Help browser
doc xlsread
<xlswrite> - Stores numeric array or cell array in Excel workbook.
XLSWRITE Stores numeric array or cell array in Excel workbook.
[SUCCESS,MESSAGE]=XLSWRITE(FILE,ARRAY,SHEET,RANGE) writes ARRAY to the Excel
workbook, FILE, into the area, RANGE in the worksheet specified in SHEET.
FILE and ARRAY must be specified. If either FILE or ARRAY is empty, an
error is thrown and XLSWRITE terminates. The first worksheet of the
workbook is the default. If SHEET does not exist, a new sheet is added at
the end of the worksheet collection. If SHEET is an index larger than the
number of worksheets, new sheets are appended until the number of worksheets
in the workbook equals SHEET. The size defined by the RANGE should fit the
size of ARRAY or contain only the first cell, e.g. 'A2'. If RANGE is larger
than the size of ARRAY, Excel will fill the remainder of the region with
#N/A. If RANGE is smaller than the size of ARRAY, only the sub-array that
fits into RANGE will be written to FILE. The success of the operation is
returned in SUCCESS and any accompanying message, in MESSAGE. On error,
MESSAGE shall be a struct, containing the error message and message ID.
See NOTE 1.
To specify SHEET or RANGE, but not both, you can call XLSWRITE with
just three inputs. If the third input is a string that includes a colon
character (e.g., 'D2:H4'), it specifies RANGE. If it is not (e.g.,
'SALES'), it specifies the worksheet to write to. See the next two
syntaxes below.
[SUCCESS,MESSAGE]=XLSWRITE(FILE,ARRAY,SHEET) writes ARRAY to the Excel
workbook, FILE, starting at cell A1 and using SHEET as described above.
[SUCCESS,MESSAGE]=XLSWRITE(FILE,ARRAY,RANGE) writes ARRAY to the Excel
workbook, FILE, in the first worksheet and using RANGE as described above.
[SUCCESS,MESSAGE]=XLSWRITE(FILE,ARRAY) writes ARRAY to the Excel
workbook, FILE, starting at cell A1 of the first worksheet. The return
values are as for the above example.
XLSWRITE ARRAY FILE, is the command line version of the above example.
INPUT PARAMETERS:
file: string defining the workbook file to write to.
Default directory is pwd; default extension 'xls'.
array: m x n numeric array or cell array.
sheet: string defining worksheet name;
double, defining worksheet index.
range: string defining data region in worksheet, using the Excel
'A1' notation.
RETURN PARAMETERS:
SUCCESS: logical scalar.
MESSAGE: struct containing message field and message_id field.
EXAMPLES:
SUCCESS = XLSWRITE('c:\matlab\work\myworkbook.xls',A,'A2:C4') will write A to
the workbook file, myworkbook.xls, and attempt to fit the elements of A into
the rectangular worksheet region, A2:C4. On success, SUCCESS will contain true,
while on failure, SUCCESS will contain false.
NOTE 1: The above functionality depends upon Excel as a COM server. In
absence of Excel, ARRAY shall be written as a text file in CSV format. In
this mode, the SHEET and RANGE arguments shall be ignored.
See also xlsread, csvwrite.
Reference page in Help browser
doc xlswrite
<xlsfinfo> - Determine if file contains Microsoft Excel spreadsheet.