Export numeric multidimensional array

Hi All I have an MxMxT numeric array. Is it possible to export it in txt format?
Thank you, Veni

Respuestas (2)

Jan
Jan el 27 de Dic. de 2015
Editada: Jan el 27 de Dic. de 2015
Yes, why not. The question is only, which kind of format you want. E.g. this is simple:
A = rand(3,4,5);
File = fullfile(YourFolder, 'Output.txt');
fid = fopen(File, 'r');
if fid == -1, error('Cannot open file: %s', File);
fprintf(fid, '%g\n', A);
fclose(fid);
Then you get a single column of values. The information about the original dimension is lost. So perhaps you want to insert the array size as first line? Or you can create a file with M columns. Perhaps you want to insert a blank line after each MxM sub-matrix. This is up to you. The more details you specify, the more complicated is the function to import the data.
Note that text files are useful, if a human has to edit it. In all other cases binary files are better.

1 comentario

veni
veni el 28 de Dic. de 2015
Y(:,:,1) =
1 1 1
1 1 1
1 1 1
Y(:,:,2) =
1 0 0
0 1 1
0 1 1
Y(:,:,3) =
1 0 0
0 1 1
0 1 1

Iniciar sesión para comentar.

veni
veni el 28 de Dic. de 2015
Hi Jan,
Thanks for your message. For some reason I cannot figure out, the example returns an error message (Cannot open file: C:\Users\veni\Documents\MATLAB\Similarities\Output.txt as my folder is the 'C:\Users\veni\Documents\MATLAB\Similarities\').
My results are of the form Y(:,:,1) =
1 1 1
1 1 1
1 1 1
Y(:,:,2) =
1 0 0
0 1 1
0 1 1
Y(:,:,3) =
1 0 0
0 1 1
0 1 1
etc.
I had a thought of exporting them as a single time series and reshape it. But I feel that this is not an efficient way. Any ideas?
Thank you in advance. Veni

2 comentarios

Steven Lord
Steven Lord el 29 de Dic. de 2015
My guess is that you don't have write permission in that directory. To check this, try to write to a file in your TEMPDIR.
Jan
Jan el 29 de Dic. de 2015
@veni: Please explain the wanted format for the file and if you really need a text file.

Iniciar sesión para comentar.

Preguntada:

el 27 de Dic. de 2015

Comentada:

Jan
el 29 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by