how to tabulate this results using fprintf?
4 次查看(过去 30 天)
显示 更早的评论
Hi All,
I have some results but they need to be in a tabulated form. If we say;
fprintf('n a(n) TrueValue epsilont epsilona\n');
how to tabulate this results in this format? My aim is tabulate them in a format that shows 1'st column n, second column lists a(n), third column shows TrueValue, 4'th column and 5'th column shows epsilont and epsilona respectively.
I've tried something like;
fprintf('%6.6f\n%6.6f\n%6.6f\n%6.6f\n%6.6f\n',n,a(n),TrueValue,epsilont,epsilona);
But everything appeared under one column in matlab command window.
Any Ideas?
I will appreciate for any help.
Thanks already!
0 个评论
采纳的回答
Matt Fig
2012-10-24
编辑:Matt Fig
2012-10-24
Give some example values for your data...
Here is a generic example on how to make nice tabulations:
x = rand(5,1);
y = rand(5,1);
[r,t] = cart2pol(x,y);
fprintf('\n\n%11s%11s%11s%11s\n','x', 'y', 'r', 'theta');
fprintf(' %10.2f %10.2f %10.2f %10.2f\n',[x,y,r,t].');
fprintf('\n\n')
4 个评论
Matt Fig
2012-10-24
Please take the time to study the code so that you learn how to do it for yourself next time you need to do so. I would start by looking at the doc for FPRINTF. Also, you should probably learn to use anonymous functions instead of inlines...
x=0.2;
TrueValue=inline('7*(x^3)/(1-x)','x');
a(2)=0;
for n=3:1:1000
a(n)=a(n-1)+7*(x^n);
epsilona(n)=abs((a(n)-a(n-1))/a(n))*100;
Et(n)=TrueValue(0.2)-a(n);
epsilont=abs(Et/TrueValue(0.2))*100;
epsilons(n)=(0.5*10^(2-n));
if abs(epsilona(n))<epsilons(n)
break
end
end
fprintf('\n\n%18s%18s%18s%18s%18s\n','n', 'a(n)',...
'TrueValue', 'epsilont','epsilona');
T = repmat(.07,1,n);
n = [0 0 3:n];
fprintf(' %17.8f %17.8f %17.8f %17.8f %17.8f\n',...
[n;a;T;epsilont;epsilona]);
更多回答(1 个)
Ahmed Fasih
2015-1-22
See cprintf package on Mathworks File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/24093-cprintf-display-formatted-colored-text-in-the-command-window
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!