简体   繁体   English

如何在R中使用meshgrid函数创建两个矩阵?

[英]How can I create two matrices with meshgrid function in R?

I am beginer in R but I have experience in Matlab. 我是R语言的初学者,但是我有Matlab的经验。 In Matlab I could create two matrices with meshgrid function by the following way: 在Matlab中,我可以通过以下方式用meshgrid函数创建两个矩阵:

[lon, lat]=meshgrid(lon, lat) 

where lon and lat are vectors with length_lon=424 and length_lat=412. 其中lon和lat是length_lon = 424和length_lat = 412的向量。 The resulted lon and lat martices are 424x412. 产生的纬度和纬度八格为424x412。 How can I carry out this method in R? 如何在R中执行此方法? I would appreciate if you helped me! 如果您能帮助我,我将不胜感激!

It looks like there are R implementations of meshgrid available: http://www.inside-r.org/packages/cran/pracma/docs/meshgrid or http://artax.karlin.mff.cuni.cz/r-help/library/AtmRay/html/meshgrid.html 看起来有可用的R meshgrid实现: http : //www.inside-r.org/packages/cran/pracma/docs/meshgridhttp://artax.karlin.mff.cuni.cz/r-help /library/AtmRay/html/meshgrid.html

Or according to this R for MATLAB users article: 或根据此R for MATLAB用户文章:

在此处输入图片说明

I think if you want an idiomatic R solution, you should explain why you want to use meshgrid ... 我认为,如果您希望使用惯用的R解决方案,则应该解释为什么要使用meshgrid ...

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

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