Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
what's wrong in my dlmwrite?

Subject: what's wrong in my dlmwrite?

From: Kuo-Hsien

Date: 19 Feb, 2009 17:02:02

Message: 1 of 3

Dear all,

I like to append all weather files in a single file, so I use dlmwrite function here. However, the format in the single file did not match up with the original files, even I address the 'precision.' Please advice me.

Thanks,
Michael

The original file format:
  2.0040000e+03 1.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 2.1210000e+02 0.0000000e+00 2.7155000e+02 2.4000000e+01 9.7640000e+04 3.4985847e-06
   2.0040000e+03 1.0000000e+00 0.0000000e+00 3.0000000e+01 0.0000000e+00 2.1140000e+02 0.0000000e+00 2.7155000e+02 2.4000000e+01 9.7640000e+04 3.4985847e-06


The single file format after the process of "dlmwrite"
2004 1 0 0 0 212.1 0 271.55 24 97640 3.498585e-06
2004 1 0 30 0 211.4 0 271.55 24 97640 3.498585e-06


Here is my code to take care of my purposes:

delete('/Users/cks/Documents/Elora/weather/functions/Elora_met04_08_class.dat')
dlmwrite('Elora_met04_08_class.dat',Elora_met04_class,'-append','precision','%0.7g','delimiter','\t');
dlmwrite('Elora_met04_08_class.dat',Elora_met05_class,'-append','precision','%0.7g','delimiter','\t');
dlmwrite('Elora_met04_08_class.dat',Elora_met06_class,'-append','precision','%0.7g','delimiter','\t');
dlmwrite('Elora_met04_08_class.dat',Elora_met07_class,'-append','precision','%0.7g','delimiter','\t');
dlmwrite('Elora_met04_08_class.dat',Elora_met08_class,'-append','precision','%0.7g','delimiter','\t');

Subject: what's wrong in my dlmwrite?

From: Kuo-Hsien

Date: 21 Feb, 2009 17:01:01

Message: 2 of 3

"Kuo-Hsien" <mchangks@hotmail.com> wrote in message <gnk3aa$6cd$1@fred.mathworks.com>...
> Dear all,
>
> I like to append all weather files in a single file, so I use dlmwrite function here. However, the format in the single file did not match up with the original files, even I address the 'precision.' Please advice me.
>
> Thanks,
> Michael
>
> The original file format:
> 2.0040000e+03 1.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 2.1210000e+02 0.0000000e+00 2.7155000e+02 2.4000000e+01 9.7640000e+04 3.4985847e-06
> 2.0040000e+03 1.0000000e+00 0.0000000e+00 3.0000000e+01 0.0000000e+00 2.1140000e+02 0.0000000e+00 2.7155000e+02 2.4000000e+01 9.7640000e+04 3.4985847e-06
>
>
> The single file format after the process of "dlmwrite"
> 2004 1 0 0 0 212.1 0 271.55 24 97640 3.498585e-06
> 2004 1 0 30 0 211.4 0 271.55 24 97640 3.498585e-06
>
>
> Here is my code to take care of my purposes:
>
> delete('/Users/cks/Documents/Elora/weather/functions/Elora_met04_08_class.dat')
> dlmwrite('Elora_met04_08_class.dat',Elora_met04_class,'-append','precision','%0.7g','delimiter','\t');
> dlmwrite('Elora_met04_08_class.dat',Elora_met05_class,'-append','precision','%0.7g','delimiter','\t');
> dlmwrite('Elora_met04_08_class.dat',Elora_met06_class,'-append','precision','%0.7g','delimiter','\t');
> dlmwrite('Elora_met04_08_class.dat',Elora_met07_class,'-append','precision','%0.7g','delimiter','\t');
> dlmwrite('Elora_met04_08_class.dat',Elora_met08_class,'-append','precision','%0.7g','delimiter','\t');

Subject: what's wrong in my dlmwrite?

From: Steven Lord

Date: 23 Feb, 2009 15:55:32

Message: 3 of 3


"Kuo-Hsien" <mchangks@hotmail.com> wrote in message
news:gnpc0d$3or$1@fred.mathworks.com...
> "Kuo-Hsien" <mchangks@hotmail.com> wrote in message
> <gnk3aa$6cd$1@fred.mathworks.com>...
>> Dear all,
>>
>> I like to append all weather files in a single file, so I use dlmwrite
>> function here. However, the format in the single file did not match up
>> with the original files, even I address the 'precision.' Please advice
>> me.
>>
>> Thanks,
>> Michael
>>
>> The original file format:
>> 2.0040000e+03 1.0000000e+00 0.0000000e+00 0.0000000e+00
>> 0.0000000e+00 2.1210000e+02 0.0000000e+00 2.7155000e+02
>> 2.4000000e+01 9.7640000e+04 3.4985847e-06
>> 2.0040000e+03 1.0000000e+00 0.0000000e+00 3.0000000e+01
>> 0.0000000e+00 2.1140000e+02 0.0000000e+00 2.7155000e+02
>> 2.4000000e+01 9.7640000e+04 3.4985847e-06
>>
>>
>> The single file format after the process of "dlmwrite"
>> 2004 1 0 0 0 212.1 0 271.55 24 97640 3.498585e-06
>> 2004 1 0 30 0 211.4 0 271.55 24 97640 3.498585e-06
>>
>>
>> Here is my code to take care of my purposes:
>>
>> delete('/Users/cks/Documents/Elora/weather/functions/Elora_met04_08_class.dat')
>> dlmwrite('Elora_met04_08_class.dat',Elora_met04_class,'-append','precision','%0.7g','delimiter','\t');

Look at "doc fprintf" for what the precision specifier '%g' does. You don't
want it to use the most compact of %e and %f, you want to use either %e or
%f. I'll let you figure out which one you want to make the output of
DLMWRITE agree with your original file format.

*snip*

--
Steve Lord
slord@mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us