|
"Leslie McBrayer" <lmcbrayer@mathworks.com> wrote in message <h1tanq$15h$1@fred.mathworks.com>...
>
> "Geant Bepi" <timothyschru_useonlywhatsbeforeunderscore@yahoo.co.uk> wrote
> in message news:h1t8uh$sr3$1@fred.mathworks.com...
> > "us " <us@neurol.unizh.ch> wrote in message
> > <h1t5t1$89r$1@fred.mathworks.com>...
> >> "Geant Bepi" <timothyschru_useonlywhatsbeforeunderscore@yahoo.co.uk>
> >> wrote in message <h1t5e0$8gk$1@fred.mathworks.com>...
> >> > Hello !
> >> >
> >> > my code generates three arrays of results namely RM, rf and rp
> >> > I want to export these results to a single txt file separated by
> >> > columns.
> >> >
> >> > Matlab prints all results in one single column and I don't know how to
> >> > separate each result column wise.
> >> > This didn't help as well.
> >> >
> >> > fprintf(fid, 'RM = [%6.5f] \n\c',RM)
> >> > fprintf(fid,'rf = [%6.5f] \n\c',rf)
> >> > fprintf(fid,'rp = [%6.5f] \t\c',rp)
> >> >
> >> > neither this;
> >> >
> >> > fid = fopen('particle_location.txt','wt');
> >> > formatSpecifier = repmat('%6.5f\t', 1, size(fid, 3));
> >> > formatSpecifier = [formatSpecifier '\n'];
> >> > fprintf(fid,'observed particles \n\n')
> >> > fprintf(fid, formatSpecifier, RM.')
> >> > fprintf(fid, formatSpecifier, rf.')
> >> > fprintf(fid, formatSpecifier, rp.')
> >> > fclose(fid)
> >> >
> >> > any advise is highly appreciated !
> >> >
> >> > thanks heaps!
> >>
> >> this FEX contribution may be helpful...
> >>
> >> http://www.mathworks.com/matlabcentral/fileexchange/23840
> >>
> >> us
> >
> > I am so dumb with Matlab.
> > I cant understand how to use the cprintf syntax to get what I wanted.
> >
> > on the other hand did you understand my question.
> >
> > appreciate your advise with a nice explanation :)
>
> If you're looking for output in single columns, such as:
>
> RM rf rp
> .xxxxx .xxxxx .xxxxx
> .xxxxx .xxxxx .xxxxx
> ...
>
> I'd suggest concatenating your results into a single matrix. fprintf prints
> the values in column order, but you want to specify rows of output, so make
> sure that the matrix looks like the transpose of the file you want to print.
>
> For example, if RM, rf, and rp are all row vectors:
>
> results = [RM; rf; rp];
> fid = fopen('particle_location.txt','wt');
>
> % headers
> fprintf(fid, 'observed particles \n\n');
> fprintf(fid, '%6s\t%6s\t%6s\t\n', 'RM', 'rf', 'rp');
>
> % tab-separated columns of results
> fprintf(fid, '%6.5f\t%6.5f\t%6.5f\n', results);
>
> fclose(fid);
>
wow Leslie!! you understood me!!
you are the man !
thanks a lot..
|