From: Ehud Eilon on 21 Dec 2008 09:25 Hello, I'm trying to create an output file from an array with 17 Columns. Since I want to keep fixed length columns, I use fprintf with formatted strings and specifics numbers of spaces. I print row after row with a for loop. (example: for k=1:1:rows fprintf(fid,' %12.5f %13.5f 12.5f .....%9.5f',Table(k,1),Table(k,2),...Table(k,17)); end ) However, my output file is somehow truncated; After the seventh column in each row the formatted string is ignored, including the newline syntax in the end, and I get a complete mess. What's the problem? Thanks, Ehud
From: Walter Roberson on 21 Dec 2008 12:30 Ehud Eilon wrote: > for k=1:1:rows > fprintf(fid,' %12.5f %13.5f 12.5f .....%9.5f',Table(k,1),Table(k,2),...Table(k,17)); > end You have missed the '%' before the third format specification in this example. Perhaps you missed a '%' in your real code as well. -- ..signature note: I am now avoiding replying to unclear or ambiguous postings. Please review questions before posting them. Be specific. Use examples of what you mean, of what you don't mean. Specify boundary conditions, and data classes and value relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?
From: Image Analyst on 21 Dec 2008 12:48 "Ehud Eilon" <ehudeilon(a)gmail.com> wrote in message <giljk0$fab$1(a)fred.mathworks.com>... > Hello, > > I'm trying to create an output file from an array with 17 Columns. > Since I want to keep fixed length columns, I use fprintf with formatted strings and specifics numbers of spaces. I print row after row with a for loop. > > (example: > for k=1:1:rows > fprintf(fid,' %12.5f %13.5f 12.5f .....%9.5f',Table(k,1),Table(k,2),...Table(k,17)); > end > ) > However, my output file is somehow truncated; After the seventh column in each row the formatted string is ignored, including the newline syntax in the end, and I get a complete mess. > > What's the problem? > > Thanks, > Ehud ------------------------------------------------------------------------------ Ehud: By the way, you don't need to specify all 17 formats if you're willing to use the same field width for each number. For example: clc; array = 1000*rand(2,17) for row = 1:size(array, 1) output = sprintf('%13.5f ', array(row,:)) end Change sprintf to fprintf to make it go to a file instead of the command window.
From: Ehud Eilon on 21 Dec 2008 13:10 Walter Roberson <roberson(a)hushmail.com> wrote in message <m2v3l.13218$%z5.2847(a)newsfe09.iad>... > Ehud Eilon wrote: > > > for k=1:1:rows > > fprintf(fid,' %12.5f %13.5f 12.5f .....%9.5f',Table(k,1),Table(k,2),...Table(k,17)); > > end > > You have missed the '%' before the third format specification in this example. > Perhaps you missed a '%' in your real code as well. > > -- > .signature note: I am now avoiding replying to unclear or ambiguous postings. > Please review questions before posting them. Be specific. Use examples of what you mean, > of what you don't mean. Specify boundary conditions, and data classes and value > relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)? But That would generate an error, or at least "12f.5" in the output, wouldn't it? I don't have access to the code right now, but I don't think I did.
From: Ehud Eilon on 21 Dec 2008 13:14
"Image Analyst" <imageanalyst(a)mailinator.com> wrote in message <gilvgi$p15$1(a)fred.mathworks.com>... > Ehud: > By the way, you don't need to specify all 17 formats if you're willing to use the same field width for each number. For example: > clc; > array = 1000*rand(2,17) > for row = 1:size(array, 1) > output = sprintf('%13.5f ', array(row,:)) > end > Change sprintf to fprintf to make it go to a file instead of the command window. Maybe I'd try it, but I still have to find a way to create equal spaces. |