Matlab 绘制一个值,该值被另外 2 个值引用

Matlab plotting a value which is referenced by another 2 values

在每次迭代中我都会得到这些值。例如;

a为2,b为3,gg(a,b)为70

a为2,b为4,gg(a,b)为72

a为2,b为5,gg(a,b)为76

我想将它们绘制在一个图中,例如 x 轴上的 'a',y 轴上的 'b',gg(a,b) 是 a 和b.我还想在颜色图中显示 gg(a,b) 值。我尝试了但还没有实现。你能帮忙吗? 这是我试过的。我不想要 3d,但不知道如何绘制。假设 gg 是一个包含 20 列和 5 行的矩阵。

gg=rand(5,20);
   for a=1:5
    for b=1:20
      hold on
      scatter3(gg(a,b),a,b)
      xlabel('gg(a,b)'), ylabel('a'), zlabel('b')
      colormap(jet)
      view(3)
    end
  end

我觉得应该是gg=rand(5,20);

这是两者的(更简单的)代码:

gg = rand(5,20);
[a,b] = ndgrid(1:5,1:20);
figure
scatter(a(:),b(:),[],gg(:))
colormap(jet)
xlim([0 6])
xlabel('a')
ylabel('b')
colorbar
figure
colormap(jet)
imagesc(1:5,1:20,gg.')
xlabel('a')
ylabel('b')
axis xy
colorbar

创建: