CSV,逗号分开的文件,如果能快速的读取这些文件中的数据,无疑会帮助我们解决很多问题。

1、 只有数据的CSV文件,CSV file that includes only numbers.

As an example, create a text file, named as 'data.csv' if you prefer, which includes the following data with any editor you like.

1,  2,  3,  4
5,  6,  7,  8
9,  0,  1,  2

1) Read all the data into a 3X4 matrix.

Mat = csvread('data.csv');
disp(Mat);

2) Read part of the data with specification of the start index. What is important is the data is accessed from index 0 in the direction of row and column.

Mat = csvread('data.csv', 1, 2);
disp(Mat);

Result showing below.

7     8
1     2

3) Read only the specified range.

Mat = csvread('data.csv', 0, 1, [0,1,2,2]);
disp(Mat);

Note the starting index you specified in the second and third parameters is the same with the first two arguments in the fourth parameter matrix.

2、 How to read a CSV file containing string data items.

Create a file, named as 'datastr.csv' if you like. Add the following data.

1, 2, 3, Mine
4, 5, 6, Yours
7, 8, 9, His

One who try to use csvread shall encounter frustration. :(

I propose another solution to solve this case.

fid = fopen('datastr.csv');
dcells = textscan(fid, '%f, %f, %f, %s');
fclose(fid);
dcellneeds = dcells(1:3);
Mat = cell2mat(dcellneeds);
disp(Mat);

The result showing below.

1     2     3
4     5     6
7     8     9

Try it and good luck. :)

Matlab:如何读取CSV文件以及如何读取带有字符串数据项的CSV文件的更多相关文章

  1. Python组织文件 实践:将带有美国风格日期的文件改名为欧洲风格日期

    描述:假设有这样一个任务,你需要将文件名中含有美国风格日期(MM-DD-YYYY)的部分更换为欧洲风格日期(DD-MM-YYYY),并且需要你处理的文件多达上千个 分析:检查当前工作目录的所有文件名, ...

  2. StreamingAssets文件夹的读取异常

    1.今天在读取StreamingAssets文件夹中的文本文件的时候,出现了异常,花了一个多小时解决了,把解决结果给大家梳理一下 2.文本文件夹所在位置:在StreamingAssets文件夹中新建一 ...

  3. Jmeter实现从csv文件中随机读取数据

    一.需求 参数放在csv文件中,文件格式如下,需求每次从文件中随机读取一行数据. 二.步骤 1.在csv文件中新增加一列,pl 2.新增一个配置原件-随机数,设置如下: 50是文件数据的行数 3.新增 ...

  4. CSV文件数据如何读取、导入、导出到新的CSV文件中以及CSV文件的创建

    CSV文件数据如何读取.导入.导出到新的CSV文件中以及CSV文件的创建 一.csv文件的创建 (1)新建一个文本文档: 打开新建文本文档,进行编辑. 注意:关键字与关键字之间用英文半角逗号隔开.第一 ...

  5. C++ 把数组数据存入 CSV 文件,以及读取 CSV 文件的数据

    1. CSV-百度百科 2. 代码 #pragma once //Microsoft Visual Studio 2015 Enterprise #include<iostream> #i ...

  6. C语言进行csv文件数据的读取

    C语言进行csv文件数据的读取: #include <stdio.h> #include <string.h> #include <malloc.h> #inclu ...

  7. EpPlus读取生成Excel帮助类+读取csv帮助类+Aspose.Cells生成Excel帮助类

    大部分功能逻辑都在,少量自定义异常类和扩展方法 ,可用类似代码自己替换 //EpPlus读取生成Excel帮助类+读取csv帮助类,epplus只支持开放的Excel文件格式:xlsx,不支持 xls ...

  8. FileSystem.DeleteDirectory遇到"无法删除 文件:无法读取源文件或磁盘"

    Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(fileFolder, UIOption.AllDialogs, RecycleOpti ...

  9. .net网站的文件上传读取进度条和断点下载

    文件上传到服务器时的进度读取 //调整上传配置 AdapterInfo(info); UpfileResult result = new UpfileResult(); try { //直接使用req ...

随机推荐

  1. ●HDU 3689 Infinite monkey theorem

    题链: http://acm.hdu.edu.cn/showproblem.php?pid=3689题解: KMP,概率dp (字符串都从1位置开始) 首先对模式串S建立next数组. 定义dp[i] ...

  2. 【NOIP2015TG】solution

    链接:https://www.luogu.org/problem/lists?name=&orderitem=pid&tag=83%2C32 D1T1(magic) 题意:看题目.. ...

  3. Java多线程volatile和synchronized总结

    volatile是轻量级的synchronized,在多处理器(多线程)开发中保证了共享变量的"可见性".可见性表示当一个线程修改了一个共享变量时,另外一个线程能读到这个修改的值. ...

  4. Yii2 获取URL的一些方法

    1. 获取url中的host信息: 例如:http://www.nongxiange.com/product/2.html Yii::$app->request->getHostInfo( ...

  5. 配置文件错误导致jenkins无法启动 org.xmlpull.v1.XmlPullParserException: only 1.0 is supported as <?xml version not '1.1' (position: START_DOCUMENT seen <?xml version=\'1.1\'... @1:19)

    org.xmlpull.v1.XmlPullParserException: only 1.0 is supported as <?xml version not '1.1' (position ...

  6. vscode 搭建go开发环境的13个插件的安装

    由于网的问题 大家都不能直接go get 这里从易到难按难度给大家推荐几种方法 最简单的FQ 但是能FQ你还不能装 请问是假的FQ吗? 第一 用git 直接git反而能从那边趴下代码 但是要自己go ...

  7. web缓存之--http缓存机制

    一.web缓存可以分为数据库缓存.代理服务器缓存.浏览器缓存. 其中浏览器缓存又包含很多内容:http缓存.indexDb.cookie.localStorage等.本片只讨论http缓存相关内容. ...

  8. 使用redis做缓存

    redis常本用来作为缓存服务器.缓存的好处是减少服务器的压力,数据查询速度快.解决数据响应慢的问题. 添加缓存:只用redis的Hash数据类型添加缓存. 例如:需要在查询的业务功能中,添加缓存 1 ...

  9. python笔记二(数据类型和变量、编码方式、字符串的编码、字符串的格式化)

    一.数据类型 python可以直接处理的数据类型有:整数.浮点数.字符串.布尔值.空值. 整数 浮点数 字符串:双引号内嵌套单引号,可以输出 i'm ok. 也可以用\来实现,\n 换行 \t tab ...

  10. Web API对application/json内容类型的CORS支持

    假设有一简单架构分为前后两部分,其一是Angular构成的前端页面站点,另一个则是通过ASP.NET Web API搭建的后端服务站点.两个站点因为分别布署,所有会有CORS(Cross-Origin ...