
Функции преобразования в MATLAB
STR2DOUBLE Convert string to double precision value.
X = STR2DOUBLE(S) converts the string S, which should be an
ASCII character representation of a real or complex scalar value,
to MATLAB's double representation. The string may contain digits,
a comma (thousands separator), a decimal point, a leading + or - sign,
an 'e' preceeding a power of 10 scale factor, and an 'i' for
a complex unit.
Examples
str2double('123.45e7')
str2double('123 + 45i')
str2double('3.14159')
str2double('2.7i - 3.14')
str2double({'2.71' '3.1415'})
str2double('1,200.34')
STR2NUM Convert string matrix to numeric array.
X = STR2NUM(S) converts a character array representation of a matrix of
numbers to a numeric matrix. For example,
S = ['1 2' str2num(S) => [1 2;3 4]
'3 4']
The numbers in the string matrix S should be ASCII character
representations of a numeric values. Each number may contain digits,
a decimal point, a leading + or - sign, an 'e' preceding a power of
10 scale factor, and an 'i' for a complex unit.
NUM2STR Convert number to string.
T = NUM2STR(X) converts the matrix X into a string representation T
with about 4 digits and an exponent if required. This is useful for
labeling plots with the TITLE, XLABEL, YLABEL, and TEXT commands.
T = NUM2STR(X,N) converts the matrix X into a string representation
with a maximum N digits of precision. The default number of digits is
based on the magnitude of the elements of X.
T = NUM2STR(X,FORMAT) uses the format string FORMAT (see SPRINTF for
details).
Example:
num2str(randn(2,2),3) produces the string matrix
'-0.433 0.125'
' -1.67 0.288'
INT2STR Convert integer to string.
S = INT2STR(X) rounds the elements of the matrix X to
integers and converts the result into a string matrix.
SPRINTF Write formatted data to string.
[S,ERRMSG] = SPRINTF(FORMAT,A,...) formats the data in the real
part of matrix A (and in any additional matrix arguments), under
control of the specified FORMAT string, and returns it in the
MATLAB string variable S. ERRMSG is an optional output argument
that returns an error message string if an error occurred or an
empty matrix if an error did not occur. SPRINTF is the same as
FPRINTF except that it returns the data in a MATLAB string
variable rather than writing it to a file.
FORMAT is a string containing C language conversion specifications.
Conversion specifications involve the character %, optional flags,
optional width and precision fields, optional subtype specifier, and
conversion characters d, i, o, u, x, X, f, e, E, g, G, c, and s.
See the Language Reference Guide or a C manual for complete details.
The special formats \n,\r,\t,\b,\f can be used to produce linefeed,
carriage return, tab, backspace, and formfeed characters respectively.
Use \\ to produce a backslash character and %% to produce the percent
character.
Examples
sprintf('%0.5g',(1+sqrt(5))/2) 1.618
sprintf('%0.5g',1/eps) 4.5036e+15
sprintf('%15.5f',1/eps) 4503599627370496.00000
sprintf('%d',round(pi)) 3
sprintf('%s','hello') hello
sprintf('The array is %dx%d.',2,3) The array is 2x3.
sprintf('\n') is the line termination character on all platforms.
CHAR Create character array (string).
S = CHAR(X) converts the array X that contains positive integers
representing character codes into a MATLAB character array (the first
127 codes are ASCII). The actual characters displayed depends on the
character set encoding for a given font. The result for any elements
of X outside the range from 0 to 65535 is not defined (and may vary
from platform to platform). Use DOUBLE to convert a character array
into its numeric codes.
S = CHAR(C), when C is a cell array of strings, places each
element of C into the rows of the character array S. Use CELLSTR to
convert back.
S = CHAR(T1,T2,T3,..) forms the character array S containing the text
strings T1,T2,T3,... as rows. Automatically pads each string with
blanks in order to form a valid matrix. Each text parameter, Ti,
can itself be a character array. This allows the creation of
arbitrarily large character arrays. Empty strings are significant.
Str2mat(S1,S2,…Sn) – формирует матрицу с символьными строками S1,…,Sn
Например,
t1='aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaa'
t2='bbbbbbb bbbbbbbbbbbbbbb'
t3='cc ccc ccc'
a=str2mat(t1,t2,t3)
Результат:
a =
aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaa
bbbbbbb bbbbbbbbbbbbbbb
cc ccc ccc
STRCMP Compare strings.
STRCMP(S1,S2) returns 1 if strings S1 and S2 are the same
and 0 otherwise.
Функции в MATLAB
Пример оформления функции
function y=custimp(x1,x2)
%CUSTIMP Customized implication function for CUSTTIP.FIS.
% OUT = CUSTIMP(IN1,IN2) calculates the implication output.
% The implication operator must be able to support either one
% or two inputs, such that CUSTIMP(X1,X2) == CUSTIMP([X1 X2]).
% Copyright 1994-2000 The MathWorks, Inc.
% $Revision: 1.6 $
if nargin==1,
y=prod(x1).^2;
else
y=(x1.*x2).^2;
end
-----------------------------------------------------------------------
Здесь
PROD Product of elements.
For vectors, PROD(X) is the product of the elements of X. For
matrices, PROD(X) is a row vector with the product over each
column. For N-D arrays, PROD(X) operates on the first
non-singleton dimension.
PROD(X,DIM) works along the dimension DIM.
Example: If X = [0 1 2
3 4 5]
then prod(X,1) is [0 4 10] and prod(X,2) is [ 0
60]