使用R写入一个没有给出正确输出的.mat文件? [英] Using R to write a .mat file not giving the right output?

查看:812
本文介绍了使用R写入一个没有给出正确输出的.mat文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.csv文件,我想读入Octave(最初尝试使用csvread)。它花了太长时间,所以我试图使用R解决方法:如何从一个csv有效地读取大矩阵在八度
这是我在R:

I had a .csv file that I wanted to read into Octave (originally tried to use csvread). It was taking too long, so I tried to use R to workaround: How to read large matrix from a csv efficiently in Octave This is what I did in R:

forest_test=read.csv('forest_test.csv')
library(R.matlab)
writeMat("forest_test.mat", forest_test_data=forest_test)

然后我回到Octave并执行了这个操作:

and then I went back to Octave and did this:

forest_test = load('forest_test.mat')

给我一个矩阵,但是一个结构。

This is not giving me a matrix, but a struct. What am I doing wrong?

推荐答案

要回答您的确切问题,您使用的是 load 函数错误。如果只想将文件上的变量插入到工作空间中,则不能将其输出分配给变量。来自Octave的加载帮助文本:

To answer your exact question, you are using the load function wrong. You must not assign it's output to a variable if you just want the variables on the file to be inserted in the workspace. From Octave's load help text:


如果使用单个输出参数调用,Octave返回数据
,而不是在符号表中插入变量。如果数据
文件只包含数字(TAB或空格分隔的列),则返回一个
值的矩阵。否则,'load'返回一个
结构,成员对应于文件中变量
的名称。

If invoked with a single output argument, Octave returns data instead of inserting variables in the symbol table. If the data file contains only numbers (TAB- or space-delimited columns), a matrix of values is returned. Otherwise, 'load' returns a structure with members corresponding to the names of the variables in the file.

使用示例,按照我们的情况:

With examples, following our case:

## inserts all variables in the file in the workspace
load ("forest_test.mat");
## each variable in the file becomes a field in the forest_test struct
forest_test = load ("forest_test.mat");

但是,你发布的有关Octave的链接对于CSV文件较慢,可以参考Octave 3.2.4这是一个相当老的版本。您确认这仍然是在最近的版本(最后一次发布是3.8.2)。

But still, the link you posted about Octave being slow with CSV files makes referece to Octave 3.2.4 which is a quite old version. Have you confirmed this is still the case in a recent version (last release was 3.8.2).

这篇关于使用R写入一个没有给出正确输出的.mat文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆