From: Justme on
Hello all,
Question regarding dlmwrite. I looked through the forums and found some useful information regarding dlmwrite and fopen. I was able to use dlmwrite successfully to copy my data to a .csv. However, is there a way to insert a header for each column that you have data? I understand how to do it using fopen, fprintf, and fclose; but I am not quite sure if you can combine the dlmwrite function and fprint to get the desired result. This is what I have:

M = [time height length]
dlmwrite('c:\tmp1.csv',M,'delimiter',',','newline','pc','precision,'%12f');

Again, spits out my data, no problem. Just wondering if I can get some labels in there.

Would I also be able to use dlmwrite as part of my current script that produces multiple graphs based on data that is currently being read from a file? I suppose the biggest challenge is to coordinate the output files so that it creates .csv files based on each set of data it read.
From: us on
On Aug 3, 5:58 pm, "Justme " <sa...(a)aol.com> wrote:
> Hello all,
>    Question regarding dlmwrite.  I looked through the forums and found some useful information regarding dlmwrite and fopen.  I was able to use dlmwrite successfully to copy my data to a .csv. However, is there a way to insert a header for each column that you have data?  I understand how to do it using fopen, fprintf, and fclose; but I am not quite sure if you can combine the dlmwrite function and fprint to get the desired result. This is what I have:
>
> M = [time height length]
> dlmwrite('c:\tmp1.csv',M,'delimiter',',','newline','pc','precision,'%12f');
>
> Again, spits out my data, no problem.  Just wondering if I can get some labels in there.
>
> Would I also be able to use dlmwrite as part of my current script that produces multiple graphs based on data that is currently being read from a file? I suppose the biggest challenge is to coordinate the output files so that it creates .csv files based on each set of data it read.

a hint:
- look at the APPEND option in

help dlmwrite;

us
From: Justme on
us <us(a)neurol.unizh.ch> wrote in message <e2d5369e-d297-4f09-8815-470fbb62cb17(a)f6g2000yqa.googlegroups.com>...
> On Aug 3, 5:58 pm, "Justme " <sa...(a)aol.com> wrote:
> > Hello all,
> >    Question regarding dlmwrite.  I looked through the forums and found some useful information regarding dlmwrite and fopen.  I was able to use dlmwrite successfully to copy my data to a .csv. However, is there a way to insert a header for each column that you have data?  I understand how to do it using fopen, fprintf, and fclose; but I am not quite sure if you can combine the dlmwrite function and fprint to get the desired result. This is what I have:
> >
> > M = [time height length]
> > dlmwrite('c:\tmp1.csv',M,'delimiter',',','newline','pc','precision,'%12f');
> >
> > Again, spits out my data, no problem.  Just wondering if I can get some labels in there.
> >
> > Would I also be able to use dlmwrite as part of my current script that produces multiple graphs based on data that is currently being read from a file? I suppose the biggest challenge is to coordinate the output files so that it creates .csv files based on each set of data it read.
>
> a hint:
> - look at the APPEND option in
>
> help dlmwrite;
>
> us


Thank you us,
I discovered this not too long after I made this post and also thank you for this insight. However, My current problem seems to be that this method seems to place each character into it's own cell in excel. So if I had a for example, the word time. It would put the words T I M E in it's own cell. I tried using cellstr to alleviate this by saying either C = ['time' 'money' 'power'] or C = {time, money, power} and I still get the same results. Am I using the append feature wrong?
From: us on
On Aug 3, 7:42 pm, "Justme " <sa...(a)aol.com> wrote:
> us <u...(a)neurol.unizh.ch> wrote in message <e2d5369e-d297-4f09-8815-470fbb62c...(a)f6g2000yqa.googlegroups.com>...
> > On Aug 3, 5:58 pm, "Justme " <sa...(a)aol.com> wrote:
> > > Hello all,
> > >    Question regarding dlmwrite.  I looked through the forums and found some useful information regarding dlmwrite and fopen.  I was able to use dlmwrite successfully to copy my data to a .csv. However, is there a way to insert a header for each column that you have data?  I understand how to do it using fopen, fprintf, and fclose; but I am not quite sure if you can combine the dlmwrite function and fprint to get the desired result.. This is what I have:
>
> > > M = [time height length]
> > > dlmwrite('c:\tmp1.csv',M,'delimiter',',','newline','pc','precision,'%12f');
>
> > > Again, spits out my data, no problem.  Just wondering if I can get some labels in there.
>
> > > Would I also be able to use dlmwrite as part of my current script that produces multiple graphs based on data that is currently being read from a file? I suppose the biggest challenge is to coordinate the output files so that it creates .csv files based on each set of data it read.
>
> > a hint:
> > - look at the APPEND option in
>
> >      help dlmwrite;
>
> > us
>
> Thank you us,
>   I discovered this not too long after I made this post and also thank you for this insight. However, My current problem seems to be that this method seems to place each character into it's own cell in excel.  So if I had a for example, the word time.  It would put the words T I M E in it's own cell.  I tried using cellstr to alleviate this by saying either C = ['time' 'money' 'power'] or C = {time, money, power} and I still get the same results.  Am I using the append feature wrong?- Hide quoted text -
>
> - Show quoted text -

one of the solutions

% the data
c={
'a' 'bb' 'ccc' 'dddd'
'a1' 'b2' 'c3' 'd4'
'a a' 'b b' 'c c' 'd d'
};
fnam='foo.txt'; % <- your file name!
% the engine
c=c.';
txt=sprintf([repmat('%s\t',1,size(c,1)),'\n'],c{:});
dlmwrite(fnam,txt,'');
% the result
disp(txt)
type(fnam);

% also, this FEX submission might be helpful...

http://www.mathworks.com/matlabcentral/fileexchange/23840

us
From: Justme on
us <us(a)neurol.unizh.ch> wrote in message <c176007b-246c-47ec-9d69-758d4fd2dea0(a)d17g2000yqb.googlegroups.com>...
> On Aug 3, 7:42 pm, "Justme " <sa...(a)aol.com> wrote:
> > us <u...(a)neurol.unizh.ch> wrote in message <e2d5369e-d297-4f09-8815-470fbb62c...(a)f6g2000yqa.googlegroups.com>...
> > > On Aug 3, 5:58 pm, "Justme " <sa...(a)aol.com> wrote:
> > > > Hello all,
> > > >    Question regarding dlmwrite.  I looked through the forums and found some useful information regarding dlmwrite and fopen.  I was able to use dlmwrite successfully to copy my data to a .csv. However, is there a way to insert a header for each column that you have data?  I understand how to do it using fopen, fprintf, and fclose; but I am not quite sure if you can combine the dlmwrite function and fprint to get the desired result. This is what I have:
> >
> > > > M = [time height length]
> > > > dlmwrite('c:\tmp1.csv',M,'delimiter',',','newline','pc','precision,'%12f');
> >
> > > > Again, spits out my data, no problem.  Just wondering if I can get some labels in there.
> >
> > > > Would I also be able to use dlmwrite as part of my current script that produces multiple graphs based on data that is currently being read from a file? I suppose the biggest challenge is to coordinate the output files so that it creates .csv files based on each set of data it read.
> >
> > > a hint:
> > > - look at the APPEND option in
> >
> > >      help dlmwrite;
> >
> > > us
> >
> > Thank you us,
> >   I discovered this not too long after I made this post and also thank you for this insight. However, My current problem seems to be that this method seems to place each character into it's own cell in excel.  So if I had a for example, the word time.  It would put the words T I M E in it's own cell.  I tried using cellstr to alleviate this by saying either C = ['time' 'money' 'power'] or C = {time, money, power} and I still get the same results.  Am I using the append feature wrong?- Hide quoted text -
> >
> > - Show quoted text -
>
> one of the solutions
>
> % the data
> c={
> 'a' 'bb' 'ccc' 'dddd'
> 'a1' 'b2' 'c3' 'd4'
> 'a a' 'b b' 'c c' 'd d'
> };
> fnam='foo.txt'; % <- your file name!
> % the engine
> c=c.';
> txt=sprintf([repmat('%s\t',1,size(c,1)),'\n'],c{:});
> dlmwrite(fnam,txt,'');
> % the result
> disp(txt)
> type(fnam);
>
> % also, this FEX submission might be helpful...
>
> http://www.mathworks.com/matlabcentral/fileexchange/23840
>
> us


Thank you us,
That is a great start. I have to tweak it around a bit but thanks very much.