behaviour of "save" function by saving int16 vector

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

behaviour of "save" function by saving int16 vector

Prof. Dr. Peter Schulz
Hi,

why is octave, when using "save" for writing an int16 vector/matrix with
-ascii option,
writing the integer numbers in exponential form and not as plain integer
numbers?

I'd like to adjust this so that I only have pure integer numbers in the
file like they
are shown in the workspace window. Is it possible?

Kind regards

Peter Schulz

fs = 48000;
freq1 = 1000;
tone1 = 0.5*sin(2*pi*freq1* (1:.1*fs)/fs);
freq2 = 1011;
tone2 = 0.25*sin(2*pi*freq2* (1:.1*fs)/fs);
tone_sum = tone1 + tone2;
tone_sum_int16 = int16(round(tone_sum * 0x7fff));
save -ascii tone_mix.txt tone_sum_int16;





Reply | Threaded
Open this post in threaded view
|

Re: behaviour of "save" function by saving int16 vector

Mike Miller-4
On Fri, May 08, 2020 at 23:37:53 +0200, Prof. Dr. Peter Schulz wrote:
> why is octave, when using "save" for writing an int16 vector/matrix with
> -ascii option,
> writing the integer numbers in exponential form and not as plain integer
> numbers?

The 'save -ascii' format is intended for Matlab compatibility and is
extremely limited in what it supports.

For example, Matlab mentions that saving a character vector 'abc' with
the '-ascii' option results in

    9.7000000e+001  9.8000000e+001  9.9000000e+001

> I'd like to adjust this so that I only have pure integer numbers in the file
> like they
> are shown in the workspace window. Is it possible?

If you care about the formatting of the contents of the file, then you
should probably look into other file I/O functions. Have you tried
dlmwrite, fdisp, fprintf, or fputs for example?

Cheers,

--
mike



signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: behaviour of "save" function by saving int16 vector

Prof. Dr. Peter Schulz
hi Mike

thanks a lot for quick response, now I understand.

I finally managed it with fprintf.

I need a simple human readable format for teaching, where students should be able to import and convert data into VHDL models in an easy way

Kind regards
Peter

> Am 09.05.2020 um 04:12 schrieb Mike Miller <[hidden email]>:
>
>> On Fri, May 08, 2020 at 23:37:53 +0200, Prof. Dr. Peter Schulz wrote:
>> why is octave, when using "save" for writing an int16 vector/matrix with
>> -ascii option,
>> writing the integer numbers in exponential form and not as plain integer
>> numbers?
>
> The 'save -ascii' format is intended for Matlab compatibility and is
> extremely limited in what it supports.
>
> For example, Matlab mentions that saving a character vector 'abc' with
> the '-ascii' option results in
>
>    9.7000000e+001  9.8000000e+001  9.9000000e+001
>
>> I'd like to adjust this so that I only have pure integer numbers in the file
>> like they
>> are shown in the workspace window. Is it possible?
>
> If you care about the formatting of the contents of the file, then you
> should probably look into other file I/O functions. Have you tried
> dlmwrite, fdisp, fprintf, or fputs for example?
>
> Cheers,
>
> --
> mike