Hi I have this part of code
[row,col] = GrubbTest(CD_data_fem(:,2:end))
X=cell2mat(CD_data_fem(:,2:end))
XX = reshape(strtrim(cellstr(num2str(X(:)))), size(X));
XX(row,col) = strcat('<html><body bgcolor="FF5500" width="50px">', XX(row,col));
set(handles.uitable1,'Data',[PN_Female XX]);
row and col variable give me :
row =
25
25
25
19
25
col =
4
6
8
9
9
It color good cells but with some extra(wrong),especialy row 19 col 4,6 and 8
Any ideas? thank you Danny

 채택된 답변

Guillaume
Guillaume 2017년 5월 22일

0 개 추천

Note: There are way more powerful formatting functions than num2str and strcat, such as sprintf, the undocumented sprintfc and since R2016b, the mighty compose. Any of these would be better than what you have.
Anyway, your problem is that you're indexing with two vectors. This doesn't work the way you think. The indexed coordinates is the cartesian product of the two vectors, not the memberwise pairs. (i.e. the coordinates are {[row(1), col(1)], [row(1), col(2)], [row(1), col(3)], row(1), col(4)], [row(2), col(1)], ...}.
The fix:
XX(sub2ind(size(XX), row, col)) = ...

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2017년 5월 22일

댓글:

2017년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by