How do I convert Binary format (.bin) to ASCII format (.asc) files?

I'm using 2 functions to translate some Binary format (.bin) to ASCII format (.asc). I want to make this programs in a loop to do it faster.
What I have:
Function 1: this function receive the input file in (.bin) and make a mesh of it. Function 2: this function receive the output file name (.as), the mesh from the function 1, and 2 more variable.
I try doing this:
for i = 1:14 fid = fopen(sprintf('C:\Users\Solines\Documents\MATLAB\2011-05-14-%d.bin',i)); %% Funcions %% fclose(fid); doesn't work. Suggestions?

1 comentario

Jan
Jan el 6 de Jul. de 2011
What exactly means "doesn't work"? Do you get an error message - if yes, which one?

Iniciar sesión para comentar.

Respuestas (1)

Voss
Voss el 27 de Dic. de 2021
backslash ('\') is an escape character in sprintf format strings, so if you want to use a string with backslashes in it in sprintf, you either need to use double-backslash to escape the escape character, or better, pass the string with the backslashes in it as an argument to sprintf, like this:
my_dir = 'C:\Users\Solines\Documents\MATLAB\';
for i = 1:14
fid = fopen(sprintf('%s2011-05-14-%d.bin',my_dir,i));
% do stuff
fclose(fid);
end

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 5 de Jul. de 2011

Respondida:

el 27 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by