MATLAB: A problem about sprintf, array and concetnation

arrayconcatenationMATLABsprintf

i need a hope about this code, there's a mistake but i just can't figured it out..
i need the result:
out2=
[SemenPadang vs persiwa, SemenPadang vs persipura, PSPS vs ... SemenPadang, bye, Persisam vs semen padang;
PSPS vs Persipura, PSPS vs Persiwa, PSPS vs SemenPadang, bye, ...
BontangFc vs PSPS ]
teams = {'SemenPadang','PSPS','Sriwijaya','Persija','PelitaJaya','Persib','Persijap','Persibo','Arema','Persema','Persela','Deltras','Persiba','PSM','BontangFC','Persisam','Persiwa','Persipura'};
out2 =
[17 18 -2 0 -3 -4 5 6 -7 -8 9 10 -11 -12 13 14 -15 -16;
18 17 1 0 -4 -3 6 5 -8 -7 10 9 -12 -11 14 13 -16 -15 ]
ab = cat(2, teams, teams);
[brs, klm]= size(out2);
for b2= 1:brs
for k2= 1:klm
if out2(b2, k2) > 0
out2(b2, k2)= sprintf('%s vs %s\n', ab{b2}, ab{abs(out2(b2, k2))}); % when out2 is positive,
elseif out2(b2, k2) < 0
out2(b2, k2)= sprintf('%s vs %s\n', ab{abs(out2(b2, k2))}, ab{b2}); % it work's on single elements
else
out2(b2, k2)= sprintf('bye');
end
end
end
thx for attention and guidance..

Best Answer

sprintf() results in strings, which are character arrays. You cannot store an entire character array into a single location of a numeric array such as out2. In order to store a character array into a location designated with just two subscripts, you have to be storing into a cell array, such as
out3{b2, k2} = sprintf('%s vs %s\n', ab{abs(out2(b2, k2))}, ab{b2});