add two number and create the text file with the result in it
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi All, I want to create a very small program which gives the result in an excel sheet or text file. for example it does (2+3) and create a text file in a directory and gives the result (5) in the text file. My MATLAB version is 2011.
Thanks
댓글 수: 0
채택된 답변
Hossein
2012년 4월 20일
Hi, first create a file using fopen function. It opens/creates to read/write. Because you wanna write use 'w' as permission. fopen returns the file ID.
fileID=fopen('c:\blahblah\mytext.txt','w');
then use fprintf function to write txt into your file. If you don't specify file ID, matlab will display the result in the command window.
fprintf(fileID,formatdata,data);
you need to format your data before sending it to txt file. Let say data is data=[1, 2.3333]; then you do the following:
fprintf(fileID,'%d %f',data);
%d is used for integers and %f for the float type data. for more details get help on fprintf, fopen.
There might be easier way when you have a large data file. But I can't think of anything except writing a loop and changing the cursor position in file.
추가 답변 (1개)
Srinivas
2012년 4월 20일
help xlswrite
help fprintf
may be you can do quick google search for this
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!