我正在做一个大学项目,我需要绘制一个矩阵单元格的图形,并根据其值用颜色填充它们,但我对颜色矩阵有很多问题,因为我无法将其用作填充函数的输入。
这样做的目的是获得类似于下图的内容,但我在代码坐标中添加了一些限制。
function [ output_args ] = drawMatrix(Table)
[m,n]=size(Table); %Get the size of the matrix;
X = 1-0.5:1:n+0.5; %Array with the X coordinates of each cell.
Y = 1-0.5:1:m+0.5; %Array with the Y coordinates of each cell.
C = repmat('w',[m,n]); %Color matrix to represent the color of each single cell, originally all in white.
[x,y]=meshgrid(X,Y); %Creates the coordinates of the cells of the matrix.
for a=1:m
for b=1:n
if Table (a,b) == 1
C(a,b)='b'; % If the value of the original cell is 1, the color is changed to blue.
end
end
end
photo = fill(x', y', C)
输入矩阵为:
[0, 0, 1, 1, 0;
0, 1, 1, 0, 0;
0, 0, 1, 0, 0;
1, 0, 0, 0, 0]
我收到以下错误:
使用时出错
fill
中的错误
color/linetype
论点
中的错误
drawMatrix
(第20行)
photo = fill(x', y', C);