Code covered by the BSD License  

Highlights from
UIMAGE - UIMAGESC

4.875

4.9 | 8 ratings Rate this file 47 Downloads (last 30 days) File Size: 3.36 KB File ID: #11368
image thumbnail

UIMAGE - UIMAGESC

by Frederic Moisy

 

12 Jun 2006 (Updated 30 Jan 2012)

Display image with non-linearly spaced axis.

| Watch this File

File Information
Description

UIMAGE(X,Y,C) displays matrix C as an image, using the vectors X and Y to specify the X and Y coordinates. X and Y may be unevenly spaced vectors, but must be increasing. The size of C must be LENGTH(Y)*LENGTH(X). (Most probably you'll want to display C' instead of C).
 
Contrary to Matlab's original IMAGE function, here the vectors X and Y do not need to be linearly spaced. Whereas Matlab's IMAGE function linearly interpolates the X-axis between X(1) and X(end), ignoring all other values (idem for Y), here UIMAGE allows for X and/or Y to be unevenly spaced vectors, by locally stretching the matrix C (ie, by duplicating some elements of C) for larger X and/or Y intervals.

Use UIMAGESC to scale the data using the full colormap. The syntax for UIMAGESC(X,Y,C,...) is the same as IMAGESC(X,Y,C,...).
 
Typical uses:
- Plotting a spatio-temporal diagram (T,X), with unevenly spaced time intervals for T (eg, when some values are missing, or when using a non-constant sampling rate).
- Plotting a set of power spectra with frequency in log-scale.

Example:
 c = randn(50,20); % Random 50x20 matrix
 x = logspace(1,3,50); % log-spaced X-axis, between 10 and 1000
 y = linspace(3,8,20); % lin-spaced Y-axis, between 3 and 8
 uimagesc(x,y,c'); % displays the matrix

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (12)
13 Jun 2006 RALIHALIZARA Julliard

BEautifull idea!

09 Mar 2008 Sven Holcombe

Excellent work. Piggybacks neatly on core matlab image() and imagesc() functions so I can simply replace these calls. If my input is in fact perfectly linear, then these calls are used directly without further processing. Thank you.

28 Mar 2008 Dhanya parameshwaran

Thanks Frederic. Clever trick , works perfectly!

24 Aug 2009 Gabriel Akira Schreiber

Oh soo cool! Just what I needed.Very nicely done.

15 Jun 2010 Jon-Fredrik Hopperstad

Excellent work. This was exactly what I was looking for. I just did 15 query-replace for 'imagesc' in my code and it works beautifully. Thanks!

14 Jun 2011 Janti

If you need to have both axis in logspace you get an error.

please add the following in the for loop in uimage.m line:120

indi = find(x<=xe(i));
indi = min(indi,length(y));
indj = find(y<=ye(j));
indj = min(indj,length(x));
ce(j,i) = c(indi(end), indj(end));

Thanks for this m file!

19 Jan 2012 Tim

I just debugged an error similar to that of Janti.... I think the i,j indexing is wrong in line 122. See below..

% ce(j,i) = c(indi(end), indj(end)); % original version
ce(j,i) = c(indj(end), indi(end)); % "corrected" version

31 Jan 2012 Bjorn Gustavsson

Just a question: What improved features does this provide compared to simply calling:

pcolor(x,y,c),shading flat,axis ij

31 Jan 2012 Frederic Moisy

Oooooooh... I must admit that Bjorn Gustavsson is totally right. This submission actually mimick to behavior of pcolor. Thank you for your remark, and sorry for this false good idea...
F.

31 Jan 2012 Rob Campbell

It's still a good idea. It's just a redundant good idea ;)

06 Feb 2012 Oliver Woodford  
06 Feb 2012 Oliver Woodford

pcolor creates patch objects, which can create problems when exporting using the painters renderer. This method allows images with non-linear axes to be rendered as images, which export much better.

Please login to add a comment or rating.
Updates
13 Jun 2006

help text improved

05 Sep 2006

submissions UIMAGE and UIMAGESC
are now merged into a single zip
file.

30 Jan 2012

Bug fixed when both X and Y axis are not linearly spaced (thank you Janti and Tim!!)

Tag Activity for this File
Tag Applied By Date/Time
specialized Frederic Moisy 22 Oct 2008 08:29:29
plotting Frederic Moisy 22 Oct 2008 08:29:29
uimagesc image uneven non linear axis Frederic Moisy 22 Oct 2008 08:29:29

Contact us at files@mathworks.com