In MATLAB: convert your A
to a dataset and use export()
function to create a text file (in stead of .mat file). Note that your column and row names must be cells of strings but not numeric vectors.
As your A.in
is a numeric matrix:
A.rows = [11,12,13,14,15]; %# numeric vector
A.cols = {'A','B','C','D','E'}; %# cell of strings
A.in = magic(5); %# numeric matrix
DS = mat2dataset(A.in,'VarNames',A.cols, 'ObsNames',cellstr(num2str(A.rows')));
export(DS,'file','A.txt')
Name for your file as you desire, e.g. 'A.txt'.
You may check the contents of your file, called "A.txt" by:
type A.txt
In R choose the folder with your 'A.txt'
file and use function read.table()
:
A <- read.table('A.txt',header = TRUE)
rownames(A) <- A$Observations
A$Observations <- NULL
Explore your desired MATLAB variable in R:
head(A)
# A B C D E
# 11 17 24 1 8 15
# 12 23 5 7 14 16
# 13 4 6 13 20 22
# 14 10 12 19 21 3
# 15 11 18 25 2 9
Please note that in the example you provided, your data is in A.rows
, and row names are in A.in
.