From: CyberFrog on 17 Apr 2010 15:59 Hi, okay I have now done the legwork of manipulating all the datasets and generated a nice 300 x 300 cell array of numbers but they're classed as characters even though they actually numbers. I have now printed this array into a file, again in the same dimensions as my cell array, however, even after trimming each and every element which went into the array the columns in my file seem to skew randomly. So my final loop for printing is: [M,N] = size(my_data); for i=1:M for j=1:N fprintf(fid, '%s\t',my_data{i,j}); end fprintf(fid, '\n'); end Obviously when using the tab option it will only start from the last character it has printed, and if each and every eleemnt has a range of characters the tab wil finish at various points along each column. Is there anyway neat trick to make sure after printing to a file all elements are alligned?? Thanks CF
From: Rune Allnor on 17 Apr 2010 16:26 On 17 apr, 21:59, "CyberFrog" <domle...(a)hotmail.com> wrote: > Hi, > okay I have now done the legwork of manipulating all the datasets and generated a nice 300 x 300 cell array of numbers but they're classed as characters even though they actually numbers. I have now printed this array into a file, again in the same dimensions as my cell array, however, even after trimming each and every element which went into the array the columns in my file seem to skew randomly. So my final loop for printing is: > > [M,N] = size(my_data); > for i=1:M > for j=1:N > fprintf(fid, '%s\t',my_data{i,j}); > end > fprintf(fid, '\n'); > end > > Obviously when using the tab option it will only start from the last character it has printed, and if each and every eleemnt has a range of characters the tab wil finish at various points along each column. > > Is there anyway neat trick to make sure after printing to a file all elements are alligned?? > > Thanks > > CF Depends on the data types of the elements. The usual way to align numbers is to play with the formatting strings: >> x = pi; >> fprintf('%g\n',x) 3.14159 >> fprintf('%12.8g\n',x) 3.1415927 >> fprintf('%012.8g\n',x) 0003.1415927 and so on. But you use %s, which means you print the data as a string. In that case formatting depends on the exact contents of the string, and can not be easily controlled using formattng codes. Rune
From: CyberFrog on 17 Apr 2010 16:49 Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <0f6256c8-bca2-4a88-999c-d5d59ba07079(a)j17g2000yqa.googlegroups.com>... > On 17 apr, 21:59, "CyberFrog" <domle...(a)hotmail.com> wrote: > > Hi, > > okay I have now done the legwork of manipulating all the datasets and generated a nice 300 x 300 cell array of numbers but they're classed as characters even though they actually numbers. I have now printed this array into a file, again in the same dimensions as my cell array, however, even after trimming each and every element which went into the array the columns in my file seem to skew randomly. So my final loop for printing is: > > > > [M,N] = size(my_data); > > for i=1:M > > for j=1:N > > fprintf(fid, '%s\t',my_data{i,j}); > > end > > fprintf(fid, '\n'); > > end > > > > Obviously when using the tab option it will only start from the last character it has printed, and if each and every eleemnt has a range of characters the tab wil finish at various points along each column. > > > > Is there anyway neat trick to make sure after printing to a file all elements are alligned?? > > > > Thanks > > > > CF > > Depends on the data types of the elements. The usual way to > align numbers is to play with the formatting strings: > > >> x = pi; > >> fprintf('%g\n',x) > 3.14159 > >> fprintf('%12.8g\n',x) > 3.1415927 > >> fprintf('%012.8g\n',x) > 0003.1415927 > > and so on. > > But you use %s, which means you print the data as a string. > In that case formatting depends on the exact contents of the > string, and can not be easily controlled using formattng codes. > > Rune Ah right, yeah I decided to keep using the strings because this data was extracted from another file and so I wanted to preserve the numbers you see which is the most important thing here. Eventually this data will get manipulated in some sort of editor like spreadsheets so I guess as long as the space is there, it doesn't need to look perfect.
|
Pages: 1 Prev: Spectral content of a time domain file Next: finding root with bisection method |