Serg
Serg

Reputation: 14118

Non-uniform axis of imagesc() in Matlab

Question: is it possible to illustrate an image on non-uniform axis?

Details:

I need to illustrate a multidimensional timeseries as an image. But the time grid of this timeseries is very non-uniform. Here is an example:

m = 10;
n = 3;
t = sort(rand(m, 1));  % non-uniform time
values = randn(m, n);  % some random values

The figure, plot(t, values); handles it well.

But imagesc() converts t into uniform time between t(1) and t(end) according to documentation:

imagesc(x,y,C) displays C as an image and specifies the bounds of the x- and y-axis with vectors x and y.

Therefore, the command:

figure, imagesc(t, 1 : n, values'); colorbar;

illustrates the image on uniform time grid.

enter image description here enter image description here

Edit: It's possible to re-sample the timeseries with higher uniform resolution. But my timeseries is already very large.

Upvotes: 5

Views: 7547

Answers (3)

mc2
mc2

Reputation: 393

There is pcolor function in MATLAB. This function does exactly what you're asking.

m = 10;
n = 3;
t = sort(rand(m, 1));  % non-uniform time
values = randn(m, n);  % some random values
figure
plot(t, values);
figure
pcolor(t, 1 : n, values'); 
colorbar;

Upvotes: 5

bla
bla

Reputation: 26069

try uimagesc from the file exchange.

enter image description here

Upvotes: 4

supyo
supyo

Reputation: 3037

Solution

Try using surface for non-uniform spacing.

First, create a 3D xyz surface of the same size as your input data:

m = 10;
n = 3;
t = sort(rand(m, 1));  % non-uniform time
values = randn(m, n);  % some random values
x = repmat(t,1,n);
y = repmat(1:n,m,1);
z = zeros(size(y));

Then, colormap your values. There is a nice tool posted to the mathworks file exchange, real2rgb, that can do this for you:

cdata = real2rgb(values);  % Where size(cdata) = [m n 3]

Lastly, plot the surface. You can even get fancy and set the transparency.

surface(x,y,z,cdata,'EdgeColor','none','FaceColor','texturemap',...
  'CDataMapping','direct');
alpha(0.3)

enter image description here

Upvotes: 2

Related Questions