1

I have a .mat file I got from someone, and it's supposed to represent global gridded data. I wanted to read it as a raster in R.

Importing was ok, I was able to import using the R.matlab package

> library(R.matlab)
> library(raster)
> 
> data <- readMat("map.mat")
> str(data)
List of 1
 $ comData: num [1:360, 1:720] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
 - attr(*, "header")=List of 3
  ..$ description: chr "MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Mon May 11 09:17:06 2015                                        "
  ..$ version    : chr "5"
  ..$ endian     : chr "little"

I would have expected at least three lists, with longitude, latitude, and the data. However, it appears to only have one list comData. I have never imported data from Matlab, I am fairly new with GIS, so probably I am missing something. How can I read this dataset as a raster?

0

1 Answer 1

3

I'm making some wild assumptions here, but what does this look like:

library(raster)
mapmap <- raster(data$comData, 
                 xmn = -180, xmx = 180, ymn = -90, ymx = 90, 
                 crs = CRS('+init=EPSG:4283'))
plot(mapmap)

Does it plot sensibly?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.