how to tabulate this results using fprintf?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Otto
am 24 Okt. 2012
Beantwortet: Ahmed Fasih
am 22 Jan. 2015
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 Kommentare
Akzeptierte Antwort
Matt Fig
am 24 Okt. 2012
Bearbeitet: Matt Fig
am 24 Okt. 2012
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 Kommentare
Matt Fig
am 24 Okt. 2012
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]);
Weitere Antworten (1)
Ahmed Fasih
am 22 Jan. 2015
See cprintf package on Mathworks File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/24093-cprintf-display-formatted-colored-text-in-the-command-window
0 Kommentare
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!