필터 지우기
필터 지우기

saving matlab results

조회 수: 4 (최근 30일)
Win Thomas Halim
Win Thomas Halim 2011년 5월 4일
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

채택된 답변

Jan
Jan 2011년 5월 4일
"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
Win Thomas Halim
Win Thomas Halim 2011년 5월 4일
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 2011년 5월 4일
@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?!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andreas Goser
Andreas Goser 2011년 5월 4일
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
Win Thomas Halim
Win Thomas Halim 2011년 5월 4일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by