MATLAB Answers

How to vary the pixel size in matlab imagesc() plot?

52 views (last 30 days)
Oskar Neumann
Oskar Neumann on 23 Jun 2020
Answered: Matthew on 23 Jun 2020
I have data of a heated plate (2m x 2m = L x L) defined by a grid (x- and y-coordinates from 0 to 2 in same or different refinements) and a corresponding matrix containing the temperatures of the centres of the plates fields (the field dimensions are defined by the x- and y-grid).
The imagesc() plot function from matlab creates good results on equidistant grids since every field has the same length and width. However working with an non-equidistant grid requires to adjust all fields dimensions according to x-y-grid.
Is it possible to do this within the imagesc() function?
Code:
imagesc(x,y, sol)
set(gca,'YDir','normal')
colormap(jet(2000)); colorbar;
xlabel('x[m]')
ylabel('y[m]')
x and y are vectors containing the coordinates of the grid, sol is the matrix containing the field centres temperatures.
Plot:
[Heated Plate with equidistant grid]
[Heated Plate with non-equidistant grid]
The non-equidistant grid performs a refinement on the right side of the plate since numerical error is biggest there.
The refinement is defined by
- same discretization for 0 <= x <= L/2 (same for y)
- double fine discretization for L/2 <= x <= L*3/4 (same for y)
- four times discretization for L*3/4 <= x <= L (same for y)
As you can see, the refinement's new field dimensions are not considered which ends up ruining the visulization.
I've already tried different plot methods like surf or pcolor. Both are not well suited for a field-centre-oriented solution.
Thank's for any advice.

  0 Comments

Sign in to comment.

Answers (1)

Matthew
Matthew on 23 Jun 2020
What I understand your issue to be is that you have non-uniform spacing of you data points along the x-axis of your data and you're having issues since imagesc assumes uniformspacing.
Try the surf function.
[x_mesh y_mesh] = meshgrid(x, y);
surf(x_mesh, y_mesh, sol,'EdgeColor','none');
view(2);
Also, throw the jet color map out of the window. I recommend the parula built-in colormap or a colormap from the VIRIDIS family avalibale in the File Exchange. If you really just have to have a rainbow color map, there's going to be a map called turbo in the 2020b release.

  0 Comments

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by