首页 > 解决方案 > Matlab: Is it possible to change image axis labels automatically to fit my data?

问题描述

I'm experimenting with using imagesc function because I need to make a 2D color plot of 3D data, where the color indicates the strength of signal output for each combination of 2 inputs, and the x and y axes should represent the input parameters. I looked at this question, which is similar: How to change image axis labels

The problem is that I don't know beforehand the range of values that my input parameters will have, and they're not necessarily "nice", "round" numbers either, that can be spaced by 10 or some other integer. Worse, depending on the test that I do, my data might have the order of inputs inverted. For instance, if I manually set the x-axis to go from low to high values (as is standard), it may actually be backward from how my data actually is, if my parameter values were being input from high to low.

example of my output image using imagesc function

I included an example of the image that I got so far. The y-axis was left as default, which simply shows that I have over 180 rows in the matrix of my output signal. I changed the x-axis by using linspace to correspond to the range of input parameters from lowest to highest value. However, the image should be flipped horizontally, because I know that the yellow spot on the right should correspond to low values on the x-axis--that is, it should be on the left side.

So I need to make this happen automatically, that the strength of my output signal gets correctly matched to the combination of 2 input parameters (which are shown on the x & y axes), and the output for each combination is represented by a color on a color scale.

Is there just no way to do this using imagesc? Do I have to use the pcolor function instead? Or is there some other approach?

标签: matlabmatlab-figure

解决方案


使用该pcolor功能,我得到了我想要的。它直接将(矩阵)变量之间的直观关系转换为具有正确轴比例的图形图像。我有 3 个变量;让我们称它们f为 ,HZ。关键是制作一个颜色图,其中的值Z对应于每个唯一fH值对,类似于 x,y 坐标。所以,我制作fH矩阵(具有相同的维度),其中f所有列都是一个列向量的副本,并且H所有行都是一个行向量的副本。(Z已经是一个矩阵,具有相同的维度。)这样,如果我从两个矩阵中选择一个 i,j 元素fH我会得到一个唯一的fH对,并且可以将其映射到 中的 i,j 元素Z。然后简单地使用:

pcolor(f,H,Z)

我得到这样的图像(带有一些附加命令): f,H color plot example

轴编号标签会自动调整以匹配fH值。


推荐阅读