How can I read a Matlab file (.m) in R Studio?

Good morning to everyone,
I am trying to read a Matlab file (.m) in R Studio, not having much success. I need to transcribe some Matlab scripts to R and I don't have Matlab installed. I already tried with the "R.matlab" package, and I manage to open .mat files but not .m files. Is there any package that allows to read that kind of files?
Thank you for your help.

Can you show us the code that you use and the error-message that you get. The package description of R.matlab indicates that a Matlab installation is not necessary.

Yes, of course.

Datos_satelitales <- readMat("Practico2_satelite.m")

Error in mat5ReadTag(this) :
Unknown data type. Not in range [1, 19]: 12596
Además: Warning messages:
1: In readMat5or73Header(this, firstFourBytes = firstFourBytes) :
Unknown endian: .8. Will assume Bigendian.
2: In readMat5or73Header(this, firstFourBytes = firstFourBytes) :
Unknown MAT version tag: 14131. Will assume version 5.

Looks like readMat is for reading .mat files, not .m files.

A .m file will contain Matlab code which will probably be of no value to you because you can't run it in R.

If you really want the .m contents, you could probably read it with read.delim(file, sep = "\n") because .m files are plain text.

1 Like

Thank you very much Arthur! Using read.delim I could open the file. I know I can't run it in R, but I need to know the content of the file so I can tray to transcribe it to R lenguage.

An .m file is just text. If it's easier, you can open it in Notepad or Word.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.