Borrar filtros
Borrar filtros

how to add a header to a text file ?

1 visualización (últimos 30 días)
safa BY
safa BY el 17 de Ag. de 2018
Editada: Stephen23 el 17 de Ag. de 2018
Hello, this my code , I need to add a header to my textfile
for k=1:nbrRect
%disp('dans playcallback la nouvelle pos est');
Cellule{k}=get(rectangles(k), 'Position');
tag= CellTag(k);
% disp('x1 et y1');
x1 = Cellule{k}(1)+Cellule{k}(3)/2
y1 = Cellule{k}(2)+Cellule{k}(4)/2
fprintf(fileID,'%d;%5.3f;%5.3f;%5.3f;%5.3f;%d;%5.3f;%5.3f;\n',tag,Cellule{k}(1),Cellule{k}(2),Cellule{k}(3),Cellule{k}(4),numf,x1,y1);
end
fprintf(fileID,'%d;%5.3f;%5.3f;%5.3f;%5.3f;%d;;%5.3f;%5.3f;\n','Person ID','pos1','pos2','Width','height','X centre','Y centre'); I added this line before writing in the file but I didn't find the header in the file

Respuestas (1)

Stephen23
Stephen23 el 17 de Ag. de 2018
Editada: Stephen23 el 17 de Ag. de 2018
One problem is that your fprintf format string contains lots of the numeric format specifier %f, but you are providing inputs which are character vectors! This will not work:
fprintf(fid,'...%f...\n',...,'some char vector',...)
^^ %f is for numbers, not char vectors!
Either you will need to use the string specifier %s, something like this:
fprintf(fid,'...%s...\n',...,'some char vector',...)
^^ %s is for strings/char vectors!
Or just put all of the names directly into the format string:
fprintf(fid,'Person ID;pos1;pos2;Width;height;X centre;Y centre\n');
How to use the fprintf format strings is explained in the fprintf documentation.

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by