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 件のコメント

Sean de Wolski
Sean de Wolski 2013 年 7 月 2 日
Works fine for me. R2013a Win7x64Sp1
Walter Roberson
Walter Roberson 2013 年 7 月 2 日
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 2015 年 2 月 15 日
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.

回答 (0 件)

この質問は閉じられています。

タグ

質問済み:

2013 年 7 月 2 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by