add two number and create the text file with the result in it
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Hossein
el 20 de Abr. de 2012
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.
Más respuestas (1)
Srinivas
el 20 de Abr. de 2012
help xlswrite
help fprintf
may be you can do quick google search for this
0 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!