potential bug in fprintf when cell array begins with word "ID"

Hi,
I came across a weird phenomenon, which I don't know how to explain.
When trying to write a series of strings into a tab-delimited text file, tab delimitation does not work if the first string is the word "ID".
However, if "ID" is the 2nd instead of 1st string, and/or if it is not capitalized ("id"), everything is fine.
anybody knows why this is happening?
Thank you in advance for your help.
Best,
Sebastian
test = {'ID', 'id', 'whatever', 'hello and goodbye'};
test2 = {'id', 'id', 'whatever', 'hello and goodbye'};
test3 = {'id', 'ID', 'whatever', 'hello and goodbye'};
nameres = ['test.txt' ];
nameres = [saveDir, nameres];
fid = fopen(nameres,'wt');
for b = 1
fprintf(fid,'%s\t', test{b, 1: end-1});
fprintf(fid,'%s\n', test{b, end});
end
fclose(fid);

3 comentarios

Works fine for me. R2013a Win7x64Sp1
How are you openng the file? It could be that your system is looking into the file to figure out what it is, and is thinking that ID marks some special file type.
What I would suggest doing is using the codes isvarname and is keyword to see if ID is some special variable, function, or keyword that is already built into MATLAB. To test if it is a built in function type code which ID and see if the message it prints states whether or not it is a function. hope that helps.

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Preguntada:

el 2 de Jul. de 2013

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by