[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Formatting of digits across columns
From: |
João Rodrigues |
Subject: |
Re: Formatting of digits across columns |
Date: |
Sun, 27 Oct 2013 13:13:15 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 |
On 27-10-2013 11:17, Andreas Weber wrote:
I'm not sure if I understand your question so please provide some smaple
matrix and your desired output.
Dear Andreas
Given a =
9.1285641 56546.353 0.0000881
47.467754 913203.35 0.0001568
389.69078 9789999.2 0.0027298
2971.9594 12137606 0.0130308
30971.488 124024830 0.4291615
and setting the maximum number of significant digits n = 6 the display
should be:
9.1 57000 0.000088
47.4 913000 0.000156
389.6 9790000 0.002729
2971.9 12138000 0.013030
30971.4 124025000 0.429161
The only way I see how to do it involves eval:
b = max(floor(log10(a))) + 1;
c = max(n - b,0);
b = max(b,0);
d =
["printf(\"%",num2str(b(1)+1),".",num2str(c(1)),"f\\t%",num2str(b(2)+1),".",num2str(c(2)),"f\\t%",num2str(b(3)+1),".",num2str(c(3)),"f\\n\",chop(a\'",num2str(n),"))"]
eval(d)
I was just wondering if there was a better way, as I hear that using
eval is a bad programming practice.
Thank you,
Joao