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:
problems with saving double type data in a Matrix/Array

Subject: problems with saving double type data in a Matrix/Array

From: Syed Galib

Date: 26 May, 2008 19:39:02

Message: 1 of 5

I have performed some calculations and got some results
which are in double format. I intended to save it in an
Array(actually a 38x1 Matrix) M. I used this declaration:
double M;

then in a 2 consecutive for loops I initialized M as:
        M = [];
        format short ENG

and then I tried to save my calculations in that Matrix M.
but the problem is, while saving, the 'double' data was
rounded and made integers. So, as I have very small value
like 0.0004, I am getting 0 for that. and that 0 is saved
in M and then in the file also.
So, if anybody can help in this matter, then please, inform
me.

Thanks in advance.

regards
Galib

Subject: problems with saving double type data in a Matrix/Array

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 26 May, 2008 20:08:02

Message: 2 of 5

In article <g1f3km$6qn$1@fred.mathworks.com>,
Syed Galib <galib.cse@gmail.com> wrote:
>I have performed some calculations and got some results
>which are in double format. I intended to save it in an
>Array(actually a 38x1 Matrix) M. I used this declaration:
>double M;

>then in a 2 consecutive for loops I initialized M as:
> M = [];
> format short ENG

>and then I tried to save my calculations in that Matrix M.
>but the problem is, while saving, the 'double' data was
>rounded and made integers. So, as I have very small value
>like 0.0004, I am getting 0 for that. and that 0 is saved
>in M and then in the file also.

No, the real 0.0004 would be stored in M. The 'format' command
only affects what you see when you disp() a variable or implicitly
request to have its value displayed by placing it on a command line
without a ';' afterwards. 'format' does not affect what is really
stored in a matrix. If you were to 'format long g' and display the
same values, you would see the full value.

You did not indicate how you are "saving" the file ? What command
are you using?
--
  "Beauty, like all other qualities presented to human experience,
  is relative; and the definition of it becomes unmeaning and
  useless in proportion to its abstractness." -- Walter Pater

Subject: problems with saving double type data in a Matrix/Array

From: Steven Lord

Date: 26 May, 2008 23:12:24

Message: 3 of 5


"Syed Galib" <galib.cse@gmail.com> wrote in message
news:g1f3km$6qn$1@fred.mathworks.com...
>I have performed some calculations and got some results
> which are in double format. I intended to save it in an
> Array(actually a 38x1 Matrix) M. I used this declaration:
> double M;

Assuming you're doing this in MATLAB, this line of code will only assign the
ASCII value of the character 'M' to the variable ans. You don't need to
declare variables in MATLAB as you do in some other languages.

> then in a 2 consecutive for loops I initialized M as:
> M = [];
> format short ENG
>
> and then I tried to save my calculations in that Matrix M.
> but the problem is, while saving, the 'double' data was
> rounded and made integers. So, as I have very small value
> like 0.0004, I am getting 0 for that. and that 0 is saved
> in M and then in the file also.

Because you initialized M with the empty double array [], M is a double
array and all the entries in M are stored as double precision values. Using
the command "format short ENG" did NOT change how the data is stored, just
how the data is DISPLAYED.

I get the sense that you may be new to MATLAB, or may not have used MATLAB
for a while. If that's the case, I recommend that you read through the
Getting Started guide as an introduction or refresher. The particular
section that deals with how to work with matrices is the "Matrices and
Arrays" section:

http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f2-8955.html

--
Steve Lord
slord@mathworks.com

Subject: problems with saving double type data in a Matrix/Array

From: Syed Galib

Date: 27 May, 2008 08:03:03

Message: 4 of 5

Thank you very much for your reply. As i am new to MATLab,
I am facing this dumb types of problems. Hope you
understand me.
you asked me about the file saving. first, as I have M = []
in the loop, i was appending the calculated values like:
    M = [M fftArea1to5 fftArea1to6 fftArea1to7 fftArea2to5
fftArea2to6];

then again this types of commands 3 more times. then I was
saving this M matrix in a '.csv' file like this:

  dlmwrite('Features.csv',M,'delimiter',';','-append')

and then in the csv file and also in M i am getting all
integers.
So, if you please can help me, it'd be very good for me.

Thank you.

regards
Galib


roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g1f5b2$o1r$1@canopus.cc.umanitoba.ca>...
> In article <g1f3km$6qn$1@fred.mathworks.com>,
> Syed Galib <galib.cse@gmail.com> wrote:
> >I have performed some calculations and got some results
> >which are in double format. I intended to save it in an
> >Array(actually a 38x1 Matrix) M. I used this declaration:
> >double M;
>
> >then in a 2 consecutive for loops I initialized M as:
> > M = [];
> > format short ENG
>
> >and then I tried to save my calculations in that Matrix
M.
> >but the problem is, while saving, the 'double' data was
> >rounded and made integers. So, as I have very small
value
> >like 0.0004, I am getting 0 for that. and that 0 is
saved
> >in M and then in the file also.
>
> No, the real 0.0004 would be stored in M. The 'format'
command
> only affects what you see when you disp() a variable or
implicitly
> request to have its value displayed by placing it on a
command line
> without a ';' afterwards. 'format' does not affect what
is really
> stored in a matrix. If you were to 'format long g' and
display the
> same values, you would see the full value.
>
> You did not indicate how you are "saving" the file ? What
command
> are you using?
> --
> "Beauty, like all other qualities presented to human
experience,
> is relative; and the definition of it becomes unmeaning
and
> useless in proportion to its abstractness." -- Walter
Pater

Subject: problems with saving double type data in a Matrix/Array

From: Syed Galib

Date: 27 May, 2008 08:05:03

Message: 5 of 5

Thank you very much for your reply. and yes, I am new to
MATLab. So, i am facing this kind of dumb problems. Thanks
for your co-operation. I'm looking in the link now.
Thanks again

regards
Galib

"Steven Lord" <slord@mathworks.com> wrote in message
<g1fg4p$8tb$1@fred.mathworks.com>...
>
> "Syed Galib" <galib.cse@gmail.com> wrote in message
> news:g1f3km$6qn$1@fred.mathworks.com...
> >I have performed some calculations and got some results
> > which are in double format. I intended to save it in an
> > Array(actually a 38x1 Matrix) M. I used this
declaration:
> > double M;
>
> Assuming you're doing this in MATLAB, this line of code
will only assign the
> ASCII value of the character 'M' to the variable ans.
You don't need to
> declare variables in MATLAB as you do in some other
languages.
>
> > then in a 2 consecutive for loops I initialized M as:
> > M = [];
> > format short ENG
> >
> > and then I tried to save my calculations in that Matrix
M.
> > but the problem is, while saving, the 'double' data was
> > rounded and made integers. So, as I have very small
value
> > like 0.0004, I am getting 0 for that. and that 0 is
saved
> > in M and then in the file also.
>
> Because you initialized M with the empty double array [],
M is a double
> array and all the entries in M are stored as double
precision values. Using
> the command "format short ENG" did NOT change how the
data is stored, just
> how the data is DISPLAYED.
>
> I get the sense that you may be new to MATLAB, or may not
have used MATLAB
> for a while. If that's the case, I recommend that you
read through the
> Getting Started guide as an introduction or refresher.
The particular
> section that deals with how to work with matrices is
the "Matrices and
> Arrays" section:
>
>
http://www.mathworks.com/access/helpdesk/help/techdoc/learn_
matlab/f2-8955.html
>
> --
> Steve Lord
> slord@mathworks.com
>
>

Tags for 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