필터 지우기
필터 지우기

how to tabulate this results using fprintf?

조회 수: 4 (최근 30일)
Otto
Otto 2012년 10월 24일
답변: Ahmed Fasih 2015년 1월 22일
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!

채택된 답변

Matt Fig
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
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]);
Otto
Otto 2012년 10월 24일
that worked amazingly well! thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ahmed Fasih
Ahmed Fasih 2015년 1월 22일

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by