How do I create a colormap from an existing data set in Matlab?

痴心易碎 提交于 2019-12-14 03:25:40

问题


I currently have a 2-D contour plot in Matlab from an existing data set. I made an [x,y] mesh grid and used this mesh grid and z-data to produce a 2-d contour plot using contourf(x, y, z). My goal is to reproduce this same data as a colormap, with smooth color gradients, rather than as a 2-d contour plot, with distinct color bands.

I have tried using imagesc(x, y, z) with [x,y] as a mesh grid and without. I ended up with an error function "Attempt to execute SCRIPT imagesc as a function:"

x = 0.1:0.1:1
y = 0.1:0.1:1
[X, Y] = meshgrid( x , y )
Z = #data#
contourf( X , Y , Z )
title
xlabel
ylabel

回答1:


I'm not quite sure what's going wrong with your attempt to use imagesc... When I used your x and y and defined Z=sin(X*20)+sin(Y*20); and ran imagesc(x,y,Z) I got

Looking at the error message you're getting I suspect that you have a script somewhere saved as imagesc which is somehow overwriting the imagesc function. Try running edit imagesc and see what comes up, is it a function?

Now as far as making this smooth looking you have two options. Firstly you could just use a higher density of points as opposed to a 10x10 grid. For example

x = linspace(0,1,1000);
y = linspace(0,1,1000);
[X, Y] = meshgrid( x , y );
Z=sin(X*20)+sin(Y*20);
imagesc(x,y,Z)

gives

Alternatively, if you want/need to stick with the low density of points you can use pcolor(X,Y,Z) and then set shading interp which gives



来源:https://stackoverflow.com/questions/55986781/how-do-i-create-a-colormap-from-an-existing-data-set-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!