R外部函数persp.default(x,y,z)中的错误:无效的'z'限制 [英] R outer function Error in persp.default(x, y, z) : invalid 'z' limits

查看:224
本文介绍了R外部函数persp.default(x,y,z)中的错误:无效的'z'限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释为什么这两段代码返回两个不同的东西吗? 第一个:

could someone explain to me why these two pieces of codes return two diferent things? the first one :

x<-y<-seq(from=-1,to=1,by=0.1)
one<-function(x,y){
    x
}
z<-outer(x,y,FUN=one)
persp(x,y,z)

返回其应有的表面.

同时:

x<-y<-seq(from=-1,to=1,by=0.1)
one<-function(x,y){
    array(1, dim=length(x))
 }
 z<-outer(x,y,FUN=one)
 persp(x,y,z) 

返回值:错误的persp.default(x,y,z = external(x,y,one)):无效的'z'限制"

returns : "Error in persp.default(x, y, z = outer(x, y, one)) : invalid 'z' limits"

推荐答案

对于第二种情况,绘制平面z=1,您只需要自己指定所需的zlim,例如

For the second case, plotting the plane z=1, you just need to specify the desired zlim yourself, e.g.

persp(x,y,z,zlim=c(0,2))

persp函数希望在3维空间中进行绘制.默认设置是尝试绘制xyz的范围,但是在这种情况下z的范围是简并的.

The persp function expects to plot in a 3-dimensional space. The default is to try to plot over the ranges of x, y and z, but in this case z's range is degenerate.

这篇关于R外部函数persp.default(x,y,z)中的错误:无效的'z'限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆