我有以下代码:
tile {6} = imread ('tw.png','png');
tile {5} = imread ('twpw.png','png');
tile {4} = imread ('twpb.png','png');
tile {3} = imread ('tb.png','png');
tile {2} = imread ('tbpw.png','png');
tile {1} = imread ('tbpb.png','png');
board = zeros(8,8)
% the board image matrix is first empty (no tile )
board = [];
% we add four empty white tiles to the first row
board = [ board tile {6} tile {6} tile {6} tile {6}];
% we add four black tiles with white pawn to the second row
board = [ board ; tile {2} tile {2} tile {2} tile {2}];
figure(1);
image(board);
set (gcf ,'Position ' ,[150 150 50* c 50* r]);
但我收到错误:
使用图片时出错。
图像CData所需的数字或逻辑矩阵
为什么我的电路板不能出现?
答案 0 :(得分:1)
表达式tile {i}
中没有空格,它应该是tile{i}
。
否则它被解释为tile
(整个单元格数组),然后是{i}
(包含标量值的单元格数组),而不是使用tile{i}
索引到数组中以获取第i个细胞内容。
以下是一些代码来说明:
% cell-array of tiles
tile{1} = zeros(5,5); % black tile
tile{2} = ones(5,5); % white tile
tile{3} = ones(5,5)*0.5; % gray tile
% build a 2x3 matrix of "blocks"
board = [tile{2}, tile{1}, tile{2} ;
tile{1}, tile{3}, tile{1}];
% show as indexed image with a grayscale colormap
imagesc(board), axis image
colormap(gray(3))
h = colorbar; set(h, 'YTick',[0 0.5 1])