如何从Matlab中的现有数据集创建颜色图?

编程入门 行业动态 更新时间:2024-10-23 07:18:11
本文介绍了如何从Matlab中的现有数据集创建颜色图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前在Matlab中从现有数据集中获得了二维轮廓图.我制作了一个[x,y]网格,并使用该网格和z数据使用轮廓f(x,y,z)生成了二维轮廓图.我的目标是将相同的数据作为具有柔和的颜色渐变的色图而不是作为具有不同色带的二维轮廓图来重现.

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.

我尝试将imagesc(x,y,z)与[x,y]用作网格并没有使用.我最终得到了一个错误函数试图将SCRIPT imagesc作为函数执行:"

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

推荐答案

我不太确定您尝试使用imagesc是什么问题...当我使用您的x和y并定义Z=sin(X*20)+sin(Y*20);并运行imagesc(x,y,Z)我得到

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

查看得到的错误消息,我怀疑您有一个保存为imagesc的脚本,从而以某种方式覆盖了imagesc函数.尝试运行edit imagesc,看看会发生什么,这是一个函数吗?

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?

现在,要使外观平滑,您有两个选择.首先,您可以使用更高的点密度,而不是10x10的网格.例如

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)

给予

或者,如果您希望/需要坚持低密度的点,则可以使用pcolor(X,Y,Z),然后设置shading interp,这样可以得到

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

更多推荐

如何从Matlab中的现有数据集创建颜色图?

本文发布于:2023-07-29 11:05:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1240129.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:颜色   数据   Matlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!