[R] Saving a 3d array into a matlab file

0 views
Skip to first unread message

Minho Chae

unread,
Oct 28, 2008, 5:25:34 PM10/28/08
to r-h...@r-project.org
Dear R users,

I am tryting to save an 3d array to a matlab file like the following.

A <- array(1:24, c(2,3,4))
writeMat(filename, A=A)

But if I load the mat file from Matlab, it is not 3d matrix anymore.
Does anyone know how I can preserve the 3d structure?
Any help will be greatly appreciated.

Minho Chae

[[alternative HTML version deleted]]

______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Henrik Bengtsson

unread,
Oct 28, 2008, 6:30:45 PM10/28/08
to Minho Chae, r-h...@r-project.org
Hi,

On Tue, Oct 28, 2008 at 2:25 PM, Minho Chae <minho...@gmail.com> wrote:
> Dear R users,
>
> I am tryting to save an 3d array to a matlab file like the following.
>
> A <- array(1:24, c(2,3,4))
> writeMat(filename, A=A)
>
> But if I load the mat file from Matlab, it is not 3d matrix anymore.
> Does anyone know how I can preserve the 3d structure?
> Any help will be greatly appreciated.

This is a bug that I'll have to look into. The dimension seems to get
lost. I'll also have to fix an earlier problem with writeMat()
existing in R.matlab v1.2.2 and later. See archive how to install the
latest stable version v1.2.1. In the meanwhile you can do something
like:

writeMat(filename, list(A=A, dim=dim(A)))

and reassign the dimension manually in Matlab (I don't know how that's
done though).

FYI, readMat() is way more stable/tested than writeMat(). The only
redundancy tests I can do on writeMat() is to try to read the data
back in using readMat(). I have little time to load writeMat()
written *.MAT files in Matlab.

/Henrik

Henrik Bengtsson

unread,
Nov 1, 2008, 4:17:23 PM11/1/08
to Minho Chae, r-h...@r-project.org
Hi, a follow up on this: I've fixed the below bug in writeMat().
R.matlab v1.2.4 is now available on CRAN. Please update.

Henrik

Reply all
Reply to author
Forward
0 new messages