【问题标题】:Insert picture from file in pcolor cells在 pcolor 单元格中插入文件中的图片
【发布时间】:2016-11-29 04:30:33
【问题描述】:

我有一个矩阵a,每当我显示pcolor 时,我想将图片从我的计算机添加到某些单元格。我想在图片所在的地方添加图片。如果图片和matlab文件在同一个目录下怎么办?

代码:

 a=[
 1 0 0;
 1 1 0;
 0 0 0];

b=[NaN NaN NaN];

a = [a;b];
b = [b NaN];
b = b.';
a = [a b];

Cmap = [1 1 1];
colormap(Cmap);
pcolor(a)

我也注意到pcolor 将矩阵移动了 180 度,为什么会这样? 这是我得到的 pcolor 图:

我需要这样的东西:

您在这里看到 pcolor 单元格中的图像,我该如何完成?

【问题讨论】:

  • subplot,不是吗?
  • 什么是subplot?谢谢你的链接,我现在试试。

标签: matlab


【解决方案1】:

我会回答我自己的问题,这就是我所做的。我希望这也可以帮助其他人。

    a=[
 1 0 0 0;
 1 1 0 0;
 0 0 0 0;
 0 0 0 0];

aa = a;
ac = aa;

b=[NaN NaN NaN NaN];

a = [a;b];
b = [b NaN];
b = b.';
a = [a b];
I = imread('redirt.jpg');
J = imresize(I, 3, 'nearest');

[x , y] = size(aa);
delete(findall(gcf,'Tag','8puzzle')) 
pos=get(gca,'position'); % getting the position

% calculating position
width=pos(3)/(y); 
height =pos(4)/(x);


Cmap = [1 1 1];
colormap(Cmap);
pcolor(a)
axis off
% loop over the positions/cells you want to place image
for i=1:x
    for j=1:y
        if(aa(i,j) == 1)
            % image position
            axes('pos',[pos(1)+width*(i-1),pos(1)+height*(j-1),width,height], 'Tag','8puzzle');
            % Show image
            imshow(J)                           
        end
        if (i == 4 && j == 4)
            axes('pos',[pos(1)+width*(i-1),pos(1)+height*(j-1),width,height], 'Tag','8puzzle');
            % Show image
            imshow('vacum.jpg')
        end
    end
end
set(gca, 'Ydir', 'reverse');

图像与单元格稍有重叠,但不会干扰显示。

【讨论】:

    猜你喜欢
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 2016-08-04
    • 1970-01-01
    • 2013-06-03
    • 2011-12-05
    • 1970-01-01
    相关资源
    最近更新 更多