在给定中心坐标的白色 canvas 上在 matlab 中创建正方形

create square in matlab on white canvas given center coordinates

我是 Matlab 的新手。我需要根据文件 squares.txt 中提供给我的规格在白色 canvases 上创建正方形。文本文档包含一个具有 6 列和一些行的数字矩阵。矩阵每一行的前两个数字是要绘制的正方形的中心坐标。第三个值是宽度,最后一个值是 RGB 值。在给定中心坐标的情况下,我很难找到在 canvas 上绘制正方形的方法。

在给定中心坐标、宽度和 RGB 值的情况下绘制一个彩色正方形,看起来像:

sq = rectangle('Position', [i-width/2, j-width/2, width, width],'EdgeColor',[r g b]);

根据您的颜色值是介于 0 和 1 之间还是介于 0 和 255 之间,您可能需要将 rgb 除以 255

编辑:

不使用文件的最小示例:

width=100;
for count = 1:2
    if (count == 1)
       canvas = ones(400,400,3);
    else
        canvas = ones(300,700,3);
    end
    figure, imshow (canvas);
    rectangle('Position', [100-width/2, 200-width/2,  width, width], 
EdgeColor', [0.5 0.5 0.2]);
end