gpt4 book ai didi

r - 将 MATLAB 'imagesc' 函数转换为使用 R 的 'imagesc' 库中的 R 的 'matlab'

转载 作者:太空宇宙 更新时间:2023-11-03 20:30:27 25 4
gpt4 key购买 nike

我是 R 的新手,之前使用过 MATLAB。我正在将 MATLAB 脚本转换为在 R 下运行。到目前为止一切顺利,除了现在绘制输出图。

MATLAB

这是使用 imagesc 绘制图形的 matlab 代码:

imagesc(velocity,time,myplot,[-35, 0]);

地点:

速度:1 x 50 矩阵

时间:1 x 10 矩阵

myplot:10 x 50 矩阵

图片说明c

更多详情 can be found here

imagesc(x,y,C) displays C as an image and specifies the bounds of the x- and y-axis with vectors x and y. If x(1) > x(2) or y(1) > y(2), the image is flipped left-right or up-down, respectively. If x and y are scalars, the image is translated to the specified location (x,y) such that the upper left corner of the image starts at (x,y).

R

imagesc 的 R 版本 which can be found here

问题:

如何在 Matlab clims 部分中将数据值重现为颜色图值,可在此处找到:http://i.imgur.com/eVy6V8N.png ,这是 Matlab 示例的 [-35, 0] 部分。

它将特定范围外的数据值映射到相同的颜色限制,有效地充当图像噪声的过滤器。

这是没有 [-35, 0] clims 部分的 Matlab 和 R imagesc 函数的结果:http://i.imgur.com/DzDjrzu.png

如您所见,它们是相同的。

这是期望的结果,包含 Matlab [-35, 0] 部分:http://i.imgur.com/Qbx6jNI.png

左侧为 Matlab,右侧为 R。左边的 Matlab 图像是我想要生成的,这完全归功于脚本的 Matlab 版本上的那个进程 clims [-35, 0]

最佳答案

我认为您可以通过预处理数据获得与 clims 相同的效果,以便将范围之外的值压缩到范围限制。

z = matrix(rnorm(10*10, sd=3), 10)

z2 <- z
z2[z2 > 3] <- 3
z2[z2 < -5] <- -5

# or simply
z2 = scales::squish(z, c(-5, 3))

filled.contour(z)

enter image description here

filled.contour(z2)

enter image description here

关于r - 将 MATLAB 'imagesc' 函数转换为使用 R 的 'imagesc' 库中的 R 的 'matlab',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16937352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com