Way to output a matrix or dat file
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am new to matlab, and trying to figure out a way to ouput. I would like to output into a data file or matrix variable. I have it calculating in a for loop because it goes through a matrix of symbols I have.
symbol1 symbol2 egcitestpvalue
It doesn't appear to like when I try to mix and match numerical data with text. What is the best way to have it output versus having it go to the command window. I would like some sort of grid I can export, sort in excel, etc.
4 Commenti
Jan
il 16 Ago 2011
@Chris: Look for "cell" in the documentation for an array type, which can store objects of different size and type.
Please post an code example for your question about the dynamically sized variable.
Risposta accettata
Rick Rosson
il 17 Ago 2011
I am not sure if csvwrite will work with strings. You may need to use xlswrite instead, or you could try to create your own customized function using fprintf. For example:
function myFileExport(filename,A)
csv = fopen(filename,'w');
fprintf(csv, ... );
fprintf(csv, ... );
...
fclose(csv);
end
HTH.
Rick
0 Commenti
Più risposte (4)
Rick Rosson
il 16 Ago 2011
Hi Chris,
There are several different ways to accomplish what you are asking.
One option is to export your data to MS Excel using either csvwrite or xlswrite. For more information about these two functions:
>> doc csvwrite
OR
>> doc xlswrite
HTH.
Rick
0 Commenti
Rick Rosson
il 16 Ago 2011
Another option is to use fprintf to print formatted output to a text file rather than to the Command Window. So, for example:
x = pi;
filename = 'myfile.txt';
txt = fopen(filename,'w');
fprintf(txt,'The value of variable x is: %15.9f \n',x);
...
...
fclose(txt);
For more information:
>> doc fprintf
HTH.
Rick
0 Commenti
Rick Rosson
il 16 Ago 2011
A third option, if you want very nicely formatted output in the form of an HTML or PDF document, would be to use the publish command. This approach would require you to create a simple MATLAB script using "cell mode", comments, and commands that display your data to the Command Window. You can then call the publish command to create a formatted document in a variety of standard formats, including HTML and PDF.
For more information:
>> doc publish
HTH.
Rick
0 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!