Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 2 Jul 2013
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.
Fadi Hijaz
Fadi Hijaz on 15 Feb 2015
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.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!