I have a large data matrix in R. I used the package 'R.matlab'
to convert the data to matlab data like so:
writeMat(con="...filepath", x=data)
I have no experience with matlab so please be patient with me:
When I load the data into matlab it says I have a 1x1 struct.
I would like to get this into a matrix form. I tried:
data=struct2cell(x)
but that doesn't look quite right. The data is decimal valued numbers btw.
It looks like your data
variable in R is a data frame. Try first to convert it to a matrix before writing to mat file:
writeMat(con="...filepath", x=as.matrix(data))
Another way you may want is to convert the cell array to matrix in MATLAB:
datanum = cell2mat(data');
If you are using Jupyter notebook. I think what you have to do is first install R.matlab library using
install.packages(c('R.matlab'), repos='http://cran.us.r-project.org')
Then implement this library using
library(R.matlab)
Afterward, you may have a dataframe in R say resi
#Save in Matlab v6 format with 'writeMat'
writeMat("resi.mat", labpcexport = resi)
I now go to Matlab and call it in that particular directory by the converting the struct to cell and then cell to matrix as
resi=cell2mat(struct2cell(load('resi.mat')))
I hope that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With