0

I have 3 matrices that I have saved as a Matlab .mat file. I am trying to get a script in R the read them. Now that they are saved, I am using the R.matlab package to access the readMat() function to read the files. My .mat file is in downloads, as I can see where it saved.

I am using Matlab 2019 (v9.6). Most of the advice I have seen has recommended to use v5 or v6 file versions which I have converted my Matlab files to so it can work with the R package. The same error occurs unfortunately.

This is one of the matrices and my code that I have attemped:

library(R.matlab)
p_matrix <- readMat(p_matrix.mat)
str(p_matrix)

This is the error feedback I keep receiving:

error in readMat(p_matrix.mat) : object 'p_matrix.mat' not found

I do not know why the consistent error seems to be "object not found".

Wolfie
  • 27,562
  • 7
  • 28
  • 55
Trey
  • 19
  • 4
  • 4
    Dunno anything about readMat. Try and add “” around the p_matrix.mat? If it is the name of the file, not an object name in the r environment – Hector Haffenden Jun 09 '19 at 23:16
  • 1
    I believe @HectorHaffenden is right. To be clear, the suggestion is to change the line `p_matrix <- readMat(p_matrix.mat)` to `p_matrix <- readMat("p_matrix.mat")`. Without quotation marks, R looks for an object in your R global environment (or at least on the search path) named `p_matrix.mat`, whereas it seems you do not have such an object saved in R, but this is the file in your file system you are trying to read. In such situations, you surround the filename with quotation marks. – duckmayr Jun 09 '19 at 23:29
  • 1
    Much better explanation @duckmayr, thanks :) In addition, the R.matlab documentation has an example, which is maybe where some confusion can from, but if followed exactly you will get the desired result. See the example from [the documentation](https://www.rdocumentation.org/packages/R.matlab/versions/3.6.2/topics/readMat) – Hector Haffenden Jun 09 '19 at 23:35
  • I have tried the proposed solution and am still getting a similar error. I am checking to see if the versions are compatible with each other.. I see that the documentation you sent requires certain matlab file versions, but does not specify whether it is version dependent on R to run this package and to successfully read the matlab file. Could it be the versions of R and matlab that are causing this issue? I am using v5 for matlab and v3.5.1 in R. – Trey Jun 25 '19 at 11:05

0 Answers0