2

I would like to extract the data from a matlab .fig file using R.

I found some solutions for matlab and python.

However, I am not sure how to do it in R.

I learned that I could use R.matlab and readMat("test.fig") to load the figure in R, however, I am not sure how I could extract the data then.

Unfortunately, I could not find an example .fig file. The only page with a few example files I found was https://people.math.sc.edu/Burkardt/data/fig/fig.html, but I think these files are too old (I get an error with readMat() using these example files). Since I do not have a MATLAB licence I cannot quickly generate such a file.

captcoma
  • 1,768
  • 13
  • 29

1 Answers1

1

As you found correctly, The matlab package is the one to use. Functions to read and manipulate MATLAB files, including.fig files, are included in this package.

install.packages("matlab")
library(matlab)


file_path <- "path/to/your/test.fig"

mat_data <- readMat(file_path)

data <- mat_data$hgS_070000$children$children$properties$CData

print(data)