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. POJ2449 Remmarguts' Date

    "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. ...

  2. codefroces 612E Square Root of Permutation

    A permutation of length n is an array containing each integer from 1 to n exactly once. For example, ...

  3. [SHOI2008]小约翰的游戏John

    Description 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取 的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不 ...

  4. 【NOIP2004】虫食算

    Description 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母.来看一个简单的例子: 43#9865#045 +. 8468#6633 444455 ...

  5. hdu 2871 线段树(各种操作)

    Memory Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  6. poj3580 splay树 REVOVLE循环

    SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 12795   Accepted: 3989 Case T ...

  7. cpu,核,进程与线程

    多进程与多线程 一张图,先来回顾一下并行,并发,串行: 一.多核多线程 当我们要去买一台新电脑时,我们一般都会比较多台电脑的配置,而其中一项关键配置就是几核几线程.一般现在很多电脑都是4核8线程,甚至 ...

  8. 笔记3 装配Bean总结

    一.自动化装配bean 1.组件扫描 2.自动装配 CompactDisc.java package Autowiring; public interface CompactDisc { void p ...

  9. 备忘:MySQL中修改表中某列的数据类型、删除外键约束

    -- MySQL中修改表中某列的数据类型 ALTER TABLE [COLUMN] 表名 MODIFY 列名 列定义; -- 删除外键约束 SHOW CREATE TABLE 表名; -- 复制CON ...

  10. SecureCRT永久设置保护眼睛配色方案

    配色后效果如下: 下面开始配色 1.选项(Options)==>会话选项(Sessions options)==>终端(Terminal)==>仿真(Emulation) 按图中标注 ...