Borrar filtros
Borrar filtros

saving matlab results

4 visualizaciones (últimos 30 días)
Win Thomas Halim
Win Thomas Halim el 4 de Mayo de 2011
hi there, anyone know hot to save results to a file in matlab? suppose i had this x,y,z data that i want to save it as results.str that is openable via matlab. anyone can help? thank you very much

Respuesta aceptada

Jan
Jan el 4 de Mayo de 2011
"Put z inthe first column" is not an exact definition of the output. Do you want to write an ASCII file?
FID = fopen(FileName, 'w');
if FID < 0, error(Cannot open file); end
data = [z, y, x];
fprintf(FID, '%g %g %g\n', transpose(data));
fclose(FID);
See "help fprintf", if you want to specify another numerical format, e.g. more digits after the dot.
  2 comentarios
Win Thomas Halim
Win Thomas Halim el 4 de Mayo de 2011
hi there,
thank you for your help,
but i have a question here, at first you type:
FID=fopen(FileName,'w')
does that command ask matlab to open a file?
because here in this case i want to write a new file, not edit it. a friend of mine told me to use 'fwrite' command but i think it will not solve this case.
Jan
Jan el 4 de Mayo de 2011
@Win: Simply read "help fopen" to see, what this command does: " 'w' open file for writing; discard existing contents".
FWRITE writes binary data, FPRINTF writes ASCII data. Both could solve your problem, it only depends on your needs. If the file need not be readable by human, a binary format is more efficient. How is the ".str" format defined?!

Iniciar sesión para comentar.

Más respuestas (1)

Andreas Goser
Andreas Goser el 4 de Mayo de 2011
From your description, I'd say you have x, y, z in your MATLAB workspace. Then you can save the data with the SAVE command. The default is a so called MAT file, but you can also choose the ASCII format. See the documentation for that.
There are other ways to export. The documenation is pretty good.
  1 comentario
Win Thomas Halim
Win Thomas Halim el 4 de Mayo de 2011
thank you, but my problem here, I don't want to save the entire variables in my Matlab workspace,
here's the detail of my problem:
after some calculations, i had this x,y,z data (size 100x1 each) to be proceed into another function that read only ".str" file in order to simulate a nanomachining structures.
i want to put z in the first column, x in the 2nd column and y in the third column as results.str.
is it possible to do that?
thank you very much

Iniciar sesión para comentar.

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by