fread

使用Matlab读取二进制数据文件

淺唱寂寞╮ 提交于 2020-01-02 12:26:38
第一步:打开文件,用到的函数fopen fid=fopen('文件名',读取方式) fid:句柄值;小于0表示打开失败;大于0表示打开成功 文件名:字符串,使用单引号(本文例程'savedata.dat') 读写方式:(本文例程二进制文件只读方式打开rb) ‘r’:只读方式打开文件(默认的方式),该文件已存在。 ‘r+’:读写方式打开文件,打开后先读后写。该文件已存在。 ‘w’:打开后写入数据。该文件已存在则更新;不存在则创建。 ‘w+’:读写方式打开文件。先读后写。该文件已存在则更新;不存在则创建。 ‘a’:在打开的文件末端添加数据。文件不存在则创建。 ‘a+’:打开文件后,先读入数据再添加数据。文件不存在则创建。 注意:在打开方式后加’t’表示以文本方式打开;加‘b’表示以二进制数据方式打开;‘wb’‘wt’ fopen默认以二进制方式打开; 第二步:读取数据,用到的函数fread [data,count]=fread(fid,size,数据类型); fid:句柄值(与第一步句柄值同名对应); size:表示读取内容的大小;N(读取N个元素到一个列向量)、inf(读取整个文件)、[M,N](读数据到M×N的矩阵中,数据按列存放); 数据类型:int16、int32、double、float等等 data:读取的数据 count:读取数据的实际数量 第三步:关闭文件

R语言学习笔记之: 论如何正确把EXCEL文件喂给R处理

耗尽温柔 提交于 2020-01-02 12:24:22
博客总目录: http://www.cnblogs.com/weibaar/p/4507801.html ---- 前言: 应用背景兼吐槽 继续延续之前每个月至少一次更新博客,归纳总结学习心得好习惯。 这次的主题是 论R与excel的结合,又称 论如何正确把EXCEL文件喂给R处理 分为: 1、 xlsx包安装及注意事项 2、用vba实现xlsx批量转化csv 以及,这个的对象,针对跟我一样那些从R开始接触编程的,一直以来都是用excel做数据分析的人……编程大牛请轻拍 之所以要研究这个,是因为最近工作上接了个活,要把原来在excel端的报表迁移到R端,自动输出可视化图形,并制作PDF或PPT。 这个活可以分为四个阶段: 1)源数据整理与搭建 & 需求分析 2)依据需求,R语言数据处理及输出处理后数据+图表 3)用markdown或者其他手段自动把图表复制到报告里 4)报告使用人自己编辑整合数据。 全程要求除了数据准备不是自动化,其他都要是自动化,能省就省。。而R本身与xlsx的融合并不好。 而R读取xlsx数据,就是我遇到的第一道槛。 这个活的数据都是人工从公司网页端数据库下载后储存在xlsx里的(用sql直连数据库的权限很难开)。尝试过直接从数据库端下载csv格式,但是一来格式时有错漏,二来直接下csv格式文件大小过大(单个文件从几兆变成几十兆)

read.csv faster than data.table::fread [duplicate]

有些话、适合烂在心里 提交于 2020-01-02 09:56:59
问题 This question already has an answer here : Comparing speed of fread vs. read.table for reading the first 1M rows out of 100M (1 answer) Closed last year . across the web I can read that I should use data.table and fread to load my data. But when I run a benchmark, then I get the following results Unit: milliseconds expr min lq mean median uq max neval test1 1.229782 1.280000 1.382249 1.366277 1.460483 1.580176 10 test3 1.294726 1.355139 1.765871 1.391576 1.542041 4.770357 10 test2 23.115503

fread() reads big number as 4.076092e-309

给你一囗甜甜゛ 提交于 2019-12-31 04:38:32
问题 The original numbers are integers from 825010211307012 to 825010304926185 . fread() turns all those numbers to 4.076092e-309 . read.table works normally, but I need to read large data so I can't use it. How can I correct this error? 回答1: If you install the bit64 package then fread will use it to read these large integers: before: > fread("./bignums.txt") V1 1: 4.076092e-309 2: 4.076092e-309 Do the magic: > install.packages("bit64") Then: > fread("./bignums.txt") V1 1: 825010211307012 2:

Why does my program crash when using fread in the constructor?

你离开我真会死。 提交于 2019-12-30 14:38:35
问题 I have a small program, written in C++ that contains a class with a large array. The class looks like this: class Test { public: Test(); ... private: int myarray[45000000]; }; Now, this array is read in from a file. I would like to do this with the constructor directly, instead of bothering to call any extra functions. The array only needs to be read in once, and afterwards will not change anymore. It has the exact size specified. My constructor looks like this: Test() { memset(myarray, 0,

Using `fread` to import csv file from an archive into `R` without extracting to disk

感情迁移 提交于 2019-12-30 02:19:08
问题 I have a zip archive with several csv files in it. I would like to use fread to import selected csv files into R . With read.csv I can get the data as follows without extracting the archive. con <- unz("myarchive.zip", "file2.csv") file2 <- read.csv(con, header=T, sep=",", stringsAsFactors = FALSE) on.exit(close(con)) How to use data.table::fread to import the the data in the csv file into R from the archive without extracting it? 回答1: fread can run shell commands to preprocess the file, so

How to check if a PHP stream resource is readable or writable?

做~自己de王妃 提交于 2019-12-29 05:46:07
问题 In PHP, how do I check if a stream resource (or file pointer, handle, or whatever you want to call them) is either readable or writable? For example, if you're faced with a situation where you know nothing about how the resource was opened or created, how do you check if it's readable? And how do you check if it's writable? Based on the testing that I've done (just with regular text files using PHP 5.3.3), fread() does not throw any errors at any level when the resource is not readable. It

C-fopen,fwrite,fread,fseek,fgets,popen,access笔记

丶灬走出姿态 提交于 2019-12-27 14:58:36
FILE * fopen(const char * path,const char * mode); 所需库: <stdio.h> 返回值 FILE是C语言定义的标准数据结构,如果open()失败,则返回NULL path 路径 mode 打开模式,包括有以下几种 r 以只读方式打开文件,该文件必须存在。 r+ 以读/写方式打开文件,该文件必须存在。 rb+ 以读/写方式打开一个二进制文件,只允许读/写数据。 rt+ 以读/写方式打开一个文本文件,允许读和写。 w 打开只写文件,若文件存在则长度清为 0,即该文件内容消失,若不存在则创建该文件。 w+ 打开可读/写文件,若文件存在则文件长度清为零,即该文件内容会消失。若文件不存在则建立该文件。 a 以附加的方式打开只写文件。若文件不存在,则会建立该文件,如果文件存在,写入的数据会被加到文件尾,即文件原先的内容会被保留(EOF 符保留)。 a+ 以附加方式打开可读/写的文件。若文件不存在,则会建立该文件,如果文件存在,则写入的数据会被加到文件尾后,即文件原先的内容会被保留(原来的 EOF 符不保留)。 wb 以只写方式打开或新建一个二进制文件,只允许写数据。 wb+ 以读/写方式打开或建立一个二进制文件,允许读和写。 wt+ 以读/写方式打开或建立一个文本文件,允许读写。 at+ 以读/写方式打开一个文本文件,允许读或在文本末追加数据

PHP technique to query the APNs Feedback Server

二次信任 提交于 2019-12-27 12:54:09
问题 Can someone clarify what the APNs (Apple Push Notification) wants as far as how you query it? The docs say it starts sending as soon as the connection is made. Does this mean that I don't do an fread() on it? Here's my current code to try and read it. I did NOT put the fread() in a loop as I do not know what response indicates "no more records to read" and I didn't want an infinite loop on my server. <?php $apnsCert = 'HOHRO-prod.pem'; $streamContext = stream_context_create(); stream_context

How to read particular data from file using fread?

给你一囗甜甜゛ 提交于 2019-12-25 12:23:33
问题 Following code writes data of student into a file using fwrite and reads data using fread: struct record { char name[20]; int roll; float marks; }student; #include<stdio.h> void main() { int i; FILE *fp; fp=fopen("1.txt","wb"); //opening file in wb to write into file if(fp==NULL) //check if can be open { printf("\nERROR IN OPENING FILE"); exit(1); } for(i=0;i<2;i++) { printf("ENTER NAME, ROLL_ NO AND MARKS OF STUDENT\n"); scanf("%s %d %f",student.name,&student.roll,&student.marks); fwrite(