Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to format a long list of output so the data stays lined up?

Subject: How to format a long list of output so the data stays lined up?

From: Billy Johnson

Date: 22 Sep, 2009 14:46:19

Message: 1 of 2

My data seems to become zig-zagged as the output continues for many iterations. How do I fix this?

Code:
function sfun(x,a)
%This function computes y=1/(1-x) using series expansion
%input:
% x = value 1/(1-x) is to be evaluated
% err = approx percent error for computed result.
%Initial condition y(0)=1
format compact
format short
if abs(x)<1
y=1;
yexact = 1/(1-x)
fprintf('\t Iter. \t approx. \t\t %% of true \t\t\t %% of approx. \n');
for i = 1:50
    order=i;
    yold = y;
    y = y + (x^order);
    epst = abs((y-yexact)/yexact)*100;
    epsa = abs((y-yold)/y)*100;
    fprintf('\t %1.0d \t %10.10f \t\t %10.10f \t\t %10.10f \n',i,y,epst,epsa);
    if(epsa <= a),break,end
end

elseif abs(x)>1
    disp(' the absolute value of x must be less than one' )
end

Ouput:
well the output gets zig zagged about halfway down. When I copied it to the screen, the forum editor made it look correct. Thats why I am not visualizing it here.

Subject: How to format a long list of output so the data stays lined up?

From: dpb

Date: 22 Sep, 2009 14:48:07

Message: 2 of 2

Billy Johnson wrote:
> My data seems to become zig-zagged as the output continues for
> many iterations. How do I fix this?
>
> Code:
> function sfun(x,a)
> %This function computes y=1/(1-x) using series expansion
...
> fprintf('\t Iter. \t approx. \t\t %% of true \t\t\t %% of approx. \n');
> for i = 1:50
...
> fprintf('\t %1.0d \t %10.10f \t\t %10.10f \t\t %10.10f \n',i,y,epst,epsa);
...
> Ouput:
> well the output gets zig zagged about halfway down. When I copied it
> to the screen, the forum editor made it look correct. Thats why I am
> not visualizing it here.

Use fixed spaces instead of tabs.

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us