日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

matlab to r,matlab to R import structure

發布時間:2024/9/15 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab to r,matlab to R import structure 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題

I have a structure in matlab for example

A =

in: [200x1 double]

cols: {28x1}

rows: [200x28 double]

How do I create a data frame in R which has A.cols as the columns and A.rows as the header

and A.in as the data

I am using R.Matlab package but I get stuck when I read the mat file in, how do I do this?

Thanks for your help!

回答1:

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

rownames(A)

A$Observations

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.

來源:https://stackoverflow.com/questions/26284790/matlab-to-r-import-structure

總結

以上是生活随笔為你收集整理的matlab to r,matlab to R import structure的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。