Converting float data to binary

Hello ,
I have a question about converting floating files to binary files of data suppose that I have a sin signal:
delta_f = 2; f_max = 10^4; fe = 10*f_max; N = fe/delta_f ;
t = (1:N)/ fe; sinus = sin(2*pi*t*10);
figure (1); plot (t,sinus,'r'); title('signal sinusoidale '); xlabel('temps'); ylabel('amplitude');
save it in a file
emplacement_fichier='c:\\test.txt'; fid=fopen(emplacement_fichier,'w'); fprintf(fid,'%s \t, %s\r\n',[t; sinus]); fclose(fid);
how can I creat an other file with all this value in an other file of course I think I have to add an offset for to get only positive values isn't it ?
thanks for your help

9 comentarios

Vivek Selvam
Vivek Selvam el 17 de Oct. de 2013
Editada: Vivek Selvam el 22 de Oct. de 2013
Hi Sabeha, do you want to read back only the positive values from the file?
Jan
Jan el 17 de Oct. de 2013
  • "Floating files" is not clear.
  • Please format your code to improve the readability.
  • I do not see a connection to "binary files" in the description of the problem.
  • Please do not post code, which does not have any relation to the problem. It does not matter if the data are a sinus or simply [-1, 0, 1].
  • Why do you want to add any offset?
Sabeha
Sabeha el 22 de Oct. de 2013
% déclarer un signal sinusodale classique
delta_f = 2;
f_max = 10^4;
fe = 10*f_max;
N = fe/delta_f ;
t = (1:N)/ fe;
sinus = sin(2*pi*t*10);
figure (1);
plot (t,sinus,'r');
title('signal sinusoidale ');
xlabel('temps');
ylabel('amplitude');
% reccuperer les amplitudes du signal sinus
emplacement_fichier='c:\\test.txt';
fid=fopen(emplacement_fichier,'w');
fprintf(fid,'%s \t, %s\r\n',[t; sinus]);
fclose(fid);
Sabeha
Sabeha el 22 de Oct. de 2013
I just want to convert the generated file to a file with all the previous data in binary
Walter Roberson
Walter Roberson el 22 de Oct. de 2013
Use fwrite() instead of fprintf()
Sabeha
Sabeha el 25 de Oct. de 2013
I always have problem with fwrite
Error using fwrite
Invalid precision.
Error in Binaire (line 30)
fwrite(fid,'%s \t, %s\r\n',[t; sinus]);
fwrite() does not accept formats. You want to write in binary, correct? Binary is binary, format-less.
fwrite(fid, [t; sinus])
You do need to be careful about whether you want the binary file to be interleaved, one t then one sinus, another t another sinus, or if you want all the t then all the sinus. [t; sinus] would end up alternating the two.
Sabeha
Sabeha el 14 de Nov. de 2013
I want the same columns one for t in binary and one for sin in binary to
Walter Roberson
Walter Roberson el 14 de Nov. de 2013
Binary files do not have columns.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Preguntada:

el 17 de Oct. de 2013

Comentada:

el 14 de Nov. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by