как в матлабе записать квадратную матрицу в файл тхт?

Scout

скажите, пожалуйста, что за функция?

Lenochka00884

dmlwrite - пишет в файл
dlmread - читает из файла
Может быть есть другие варианты, не знаю.

Scout

не описка? у меня че-то таких функций вообще не находит.. :confused:

Scout

помогите, это ж банальщина для многих наверняка! Я матлаб-новичок

narkom

если собираешься использовать файл в матлабе, то есть команды load/save. Напиши в матлабе help save там подробно распишут, что и как.

Scout

не, я хочу в С использовать. Есть такая возможность?

narkom

у меня просто матлаба подрукой нет, и я не помню как они сохраняют, в каком формате. Потому как использую только в матлабе. Почитай хелп для save может есть какое-какие опции.
Кстати, я слышал, что есть в матлабе опция скомпилировать кусок кода в си, правда может это только слухи :)

Lenochka00884

>> help dlmread
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-space delimiter will produce a result with
an extra last column filled with zeros.

See also dlmwrite, textscan, load, fileformats.
Reference page in Help browser
doc dlmread
>> help dlmwrite
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, csvread, num2str, textscan, strread,
importdata, sscanf, sprintf, wk1write, wk1read.
Reference page in Help browser
doc dlmwrite
load/save c параметром -ascii тоже должно работать

Scout

спасибо, дружище! не заметил, оказывается dlm, а не dml !
2 - тоже спасибо!
Оставить комментарий
Имя или ник:
Комментарий: