Way to output a matrix or dat file
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Jan
2011 年 8 月 16 日
@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.
採用された回答
Rick Rosson
2011 年 8 月 17 日
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 件のコメント
その他の回答 (4 件)
Rick Rosson
2011 年 8 月 16 日
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 件のコメント
Rick Rosson
2011 年 8 月 16 日
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 件のコメント
Rick Rosson
2011 年 8 月 16 日
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 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!