command to store array in file

is there one command in matlab store array in file?
thanks

Antworten (1)

Jan
Jan am 3 Dez. 2011

2 Stimmen

As binary file:
X = rand(3, 4, 5);
save('FileName.mat', 'X');
As text file:
FID = fopen('FileName.txt', 'w');
if FID == -1, error('Cannot create file.'); end
fprintf(FID, '%g %g %g\n', X);
fclose(FID);
You find more examples in the documentation.

4 Kommentare

huda nawaf
huda nawaf am 3 Dez. 2011
thanks,
but it save file not properly.
x =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
in file be as
17 23 4
10 11 24
5 6 12
18 1 7
13 19 25
8 14 20
21 2 15
16 22 3
9
please badly need such command, my file with very big size, I can not use for loop
Grzegorz Knor
Grzegorz Knor am 3 Dez. 2011
Try to use the function dlmwrite.
Jan
Jan am 3 Dez. 2011
@huda nawaf: The saved file *is* properly, but your expectations are not matching. FPRINTF writes the elements columnwise, as expalined in the documentation repeatedly. If you want x appear as in the command window:
fprintf(FID, '%g %g %g %g %g\n', transpose(x));
Of course the format string '%g %g %g\n' is *not* thought for a [5x5] matrix.
huda nawaf
huda nawaf am 3 Dez. 2011
wonderful Knor
really thanks , and can read file by dlmread.
many many thanks

Melden Sie sich an, um zu kommentieren.

Kategorien

Tags

Gefragt:

am 3 Dez. 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by