strread
(Not recommended) Read formatted data from string
strread is not recommended. Use textscan instead.
Syntax
Description
A = strread( reads numeric data from input
character vector str)str into a 1-by-N vector
A, where N equals the number of whitespace-separated
numbers in str. Use this syntax with character vectors containing numeric
data.
[A,B,...] = strread( reads numeric data
from the character vector input str)str into scalar output variables
A, B, and so on. The number of output variables must
equal the number of whitespace-separated numbers in str.
[A,B,...] = strread(
reads data from str,format)str into variables A,
B, and so on using the specified format. The number of output variables
must be equal to the number of format specifiers (such as %s or
%d) in the format argument. You can read all of the
data in str to a single output variable as long as you use only one
format specifier.
The table Formats for strread lists the valid format specifiers.
[A,B,...] = strread(
reads the first str,format,N)N values from str as determined by the
format character vector, where N is an integer
greater than zero. If N is -1, then strread reads all
the values in str. When str contains only numeric
data, you can set format to the empty character vector
('').
[A,B,...] = strread(___,
customizes Name,Value)strread using Name,Value arguments. When
str contains only numeric data, you can set format
to the empty character vector ('').
Examples
Input Arguments
Name-Value Arguments
Tips
If you terminate the input character vector with a newline character (
\n),strreadreturns arrays of equal size by padding arrays of lesser size with theemptyvaluecharacter:[A,B,C] = strread(sprintf('5,7,1,9\n'),'%d%d%d', ... 'delimiter', ',', 'emptyvalue',NaN) A = 5 9 B = 7 NaN C = 1 NaNIf you remove the
\nfrom the input character vector of this example, arrayAcontinues to be a 2-by-1 array, butBandCare now 1-by-1.
Version History
Introduced in R2006a