简体   繁体   English

在 R 中的矩阵的 x、y 坐标处分配向量

[英]assign vector at x, y coordinates of a matrix in R

I am moving from MATLAB to R and have a question regarding how to assign a vector at x , y coordinates of a matrix.我正在从 MATLAB 移动到 R 并且有一个关于如何在矩阵的xy坐标处分配向量的问题。 For this, I tried with defining an array and then reading each pixel.为此,我尝试定义一个数组,然后读取每个像素。 I am stuck with reassigning values to the matrix after processing it.在处理矩阵后,我坚持将值重新分配给矩阵。 Following is my code:以下是我的代码:

GR_anom<-array(NaN,dim=c(180,360,100))
for (i in 1:180)) {
  for (j in 1:360) {
    GR_vec<-as.data.frame(GR[i,j,,drop=TRUE])
    Nonses= seasonaltrend(GR_vec,2002,2017)
    GR_anom[i,j,] <- Nonses[1]
  }
}

The line(GR_anom[i,j,] <- Nonses[1]) is written in the MATLAB format but in R it seems to work differently. line(GR_anom[i,j,] <- Nonses[1])以 MATLAB 格式编写,但在 R 中,它的工作方式似乎有所不同。 I am stuck here since long in it, can you please suggest?我卡在这里很久了,你能建议吗?

I have resolved the problem.我已经解决了这个问题。 The issue was the variable 'Nonses' is a list and therefore cannot be assigned to an array.问题是变量“Nonses”是一个列表,因此不能分配给数组。 In matlab everything is a matrix, so didn't think in that direction.在 matlab 中,一切都是矩阵,所以没有朝那个方向思考。 Thank you very much for your responses.非常感谢您的回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM