How to use fprintf to add a header when printing a matrix?

11 ビュー (過去 30 日間)
Kelsey Hideshima
Kelsey Hideshima 2015 年 2 月 15 日
回答済み: Image Analyst 2015 年 2 月 16 日
I used fprintf('%u %1.2e\n', [values]') to print the matrix, but I only got the values and no headers. I want to print the same matrix with the following column headers: T(K) and k(1/min) using fprintf.
T=(100:50:500)
k=(1:50:5)
values=[T,k]; %K,min^-1
fprintf('%u %1.2e\n', [values]')

回答 (2 件)

Jennifer Smith
Jennifer Smith 2015 年 2 月 15 日
編集済み: Jennifer Smith 2015 年 2 月 15 日
You can create a variable that formats the output, then call it in fprintf. For example:
% setup='%1s %1s';
Where "s" denotes that you can add a string.

Image Analyst
Image Analyst 2015 年 2 月 16 日
This must be a homework assignment (I'll tag it as such). I just answered virtually the same question from Sarah here: http://www.mathworks.com/matlabcentral/answers/178627#answer_168123

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by