MATLAB: Fprintf not printing correct string

debugfprintfMATLABoutput

Hello everyone,
I am trying to write a short script to make debugging some code easier but have encounter something strange. I was trying to use fprintf to write out some data to the command prompt using the following code:
str_dat = ['i1 =';'j1 =';'f1 =';'i2 =';'j2 =';'f2 =';'k1 =';'k2 ='];
dat = [i1;j1;f1;i2;j2;f2;k1;k2];
for i = 1:8
fprintf('%4s %15s \n',str_dat(i),num2str(dat(i)));
end
But for some reason the output I am getting is as follows:
i 0
j 536870912
f 2
i 1073741824
j 536870912
f 3
k -2
k 0
What happened to the '=' and the numbers in 'i2', 'j2', etc? I have never experienced this issue before.
Also, I have tried writing the data to a text file using the same code but I get the same output in the text file as well.
Thanks for your help.
Andrew

Best Answer

Change your str_dat reference to str_dat(i,:):
fprintf('%4s %15s \n',str_dat(i,:),num2str(dat(i)));