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:
Saving numbers to a file?

Subject: Saving numbers to a file?

From: Nic Roberts

Date: 29 Sep, 2011 21:17:16

Message: 1 of 3

Hi,

I am trying to save data using fopen,fprintf and then trying to read it back in in using fread but fprintf seems to save the numbers as strings of ASCII characters even when I specify '%f'.

How do write just the literal number and not have the values converted to ASCII ?

Thanks

Nic

Subject: Saving numbers to a file?

From: Wayne King

Date: 29 Sep, 2011 21:34:11

Message: 2 of 3

"Nic Roberts" wrote in message <j62n8s$e16$1@newscl01ah.mathworks.com>...
> Hi,
>
> I am trying to save data using fopen,fprintf and then trying to read it back in in using fread but fprintf seems to save the numbers as strings of ASCII characters even when I specify '%f'.
>
> How do write just the literal number and not have the values converted to ASCII ?
>
> Thanks
>
> Nic

Hi Nic, Can you just give a small example of what you mean:

fid = fopen('write_test1.txt','w','native');
test = randn(10,1);
fwrite(fid,test,'int16');
array = fread(fid,10,'int16');
class(array)
ans =

double

Wayne

Subject: Saving numbers to a file?

From: Nic Roberts

Date: 29 Sep, 2011 21:56:27

Message: 3 of 3

"Wayne King" wrote in message <j62o8i$hiu$1@newscl01ah.mathworks.com>...
> "Nic Roberts" wrote in message <j62n8s$e16$1@newscl01ah.mathworks.com>...
> > Hi,
> >
> > I am trying to save data using fopen,fprintf and then trying to read it back in in using fread but fprintf seems to save the numbers as strings of ASCII characters even when I specify '%f'.
> >
> > How do write just the literal number and not have the values converted to ASCII ?
> >
> > Thanks
> >
> > Nic
>
> Hi Nic, Can you just give a small example of what you mean:
>
> fid = fopen('write_test1.txt','w','native');
> test = randn(10,1);
> fwrite(fid,test,'int16');
> array = fread(fid,10,'int16');
> class(array)
> ans =
>
> double
>
> Wayne

Hi Wayne,

Thanks for your response as soon as I saw it I realsied I should be using fwrite and not fprintf.

Thanks

Nic

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