a problem about sprintf, array and concetnation
Show older comments
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..
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!