faridcher / ml-course

Starter code of Prof. Andrew Ng's machine learning MOOC in R statistical language
https://www.coursera.org/learn/machine-learning
170 stars 149 forks source link

Matlab file to R file (.mat to .Rda) converstion #2

Closed rajasekhar-thiru closed 7 years ago

rajasekhar-thiru commented 7 years ago

Hello Farid, I am a newbie in R; finding your Github repository very useful in coming up to speed.

Can you please help me understand how you converted a matlab file (.mat) into an R file (.Rda)

https://github.com/faridcher/ machine-learning-course/tree/ master/Starter/mlclass-ex3

from ex3data1.mat in matlab to 'ex3data1.Rda'

Thank you for the help.

faridcher commented 7 years ago

Hi Raja,

You can convert any .mat file to .rda using two lines of code:

obj <- R.matlab::readMat("ex3data1.mat")
save(obj,file = "ex3data1.rda")

just make sure to install the following package:

install.packages("R.matlab")
rajasekhar-thiru commented 7 years ago

thank you. It worked. The list2env command that you provided after load was giving an error:

list2env(data,.GlobalEnv) Error in list2env(data, .GlobalEnv) : first argument must be a named list

Problem resolved once i replaced 'data' with 'obj' obj <- R.matlab::readMat('ex3data1.mat') save(obj,file = "ex3data1.Rda") load('ex3data1.Rda') list2env(obj,.GlobalEnv) # changed from list2env(data,.GlobalEnv)

Thank you for the help.