How do I save multiple variables from the workspace as a .out file?

Basically I need to save a couple specific variables(matrices) from the workspace into a .out file. I've tried the save function but this is what happens ( http://gyazo.com/ff01c99fb76da88b3dab5653d7a8b8f6 ).
How can I make so it is readable? Thanks in advance

 Respuesta aceptada

X = rand(10);
Y = ones(3);
dlmwrite('data.out', X);
dlmwrite('data.out', Y, '-append')

5 comentarios

João
João el 28 de Nov. de 2014
Editada: João el 28 de Nov. de 2014
That does help, although it makes it so the two matrices connect making it look like one big matrix instead of two. Any way I can change that? Thank you
Thorsten
Thorsten el 28 de Nov. de 2014
Editada: Thorsten el 28 de Nov. de 2014
Write a newline before you append further matrices
dlmwrite('data.out', X);
fprintf(fopen('data.out', 'a'), '\n'); % write newline to 'data.out'
dlmwrite('data.out', Y, '-append')
João
João el 28 de Nov. de 2014
Editada: João el 28 de Nov. de 2014
What if the file name isn't defined, i.e., it is asked to the user by an input
Thank you!
You can use uiputfile():
% Get the name of the file that the user wants to save.
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = userpath
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
In Thorsten's code I think you should use an fclose() so the file does not remain open:
fid = fopen('data.out', 'at');
if fid ~= -1
fprintf(fid, '\n'); % write newline to 'data.out'
fclose(fid);
end
In this case the input is prior to the saving. How do I fix this problem?
Thank you very much!

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 28 de Nov. de 2014

Comentada:

el 28 de Nov. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by