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. bzoj3963[WF2011]MachineWorks cdq分治+斜率优化dp

    3963: [WF2011]MachineWorks Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 270  Solved: 80[Submit][S ...

  2. P2P技术详解(一):NAT详解——详细原理、P2P简介

    1. IPv4协议和NAT的由来 今天,无数快乐的互联网用户在尽情享受Internet带来的乐趣.他们浏览新闻,搜索资料,下载软件,广交新朋,分享信息,甚至于足不出户获取一切日用所需.企业利用互联网发 ...

  3. Debugging TensorFlow models 调试 TensorFlow 模型

    Debugging TensorFlow models Symbolic nature of TensorFlow makes it relatively more difficult to debu ...

  4. mvn package 和 mvn install

    刚刚准备将maven项目中一个子项目打个包,使用了mvn package.心想这个很简单嘛,没料就报错了.报错咱不怕,看看错在哪就好了. 编译出错,找不到我定义的异常类中的配置.那应该是引用父模块出来 ...

  5. SpringBoot 中 get/post 请求处理方式,以及requestboy为Json时的处理

    GET.POST方式提时, 根据request header Content-Type的值来判断: application/x-www-form-urlencoded, 可选(即非必须,因为这种情况的 ...

  6. Mysql锁机制--并发事务带来的更新丢失问题

    Mysql 系列文章主页 =============== 刚开始学习 Mysql 锁的时候,觉得 Mysql 使用的是行锁,再加上其默认的可重复读的隔离级别,那就应该能够自动解决并发事务更新的问题.可 ...

  7. js求和运算在可变参数的情况下ES3、ES5和ES6的写法区别

    //ES3.ES5的写法 function foo(){ var arr = Array.prototype.slice.call(arguments); var sum = 0; arr.forEa ...

  8. Android Support库——support annotations

    Android Support库是官方出的支持扩展库,包含了丰富的组件.工具类等,通过在Android SDK Manager中勾选以下两项来获取到. 其中,Android Support Libra ...

  9. 新版Azure CDN HTTPS加速服务正式上线

    随着网络安全问题日益得到全民重视,HTTPS网络访问协议在互联网访问中得到了广泛的使用.Azure CDN也早在一年前的2015年4月上线了HTTPS加速服务.该加速服务上线一年以来,用户使用量逐渐增 ...

  10. nginx 日志分析工具goaccess

    参考:https://www.goaccess.io/download 安装 $ wget http://tar.goaccess.io/goaccess-1.1.1.tar.gz $ tar -xz ...