比如这样一种格式化的文本文件,文件说明及下载地址:/pub/machine-learning-databases/statlog/german/ 的索引

fid = fopen('german.data', 'r');
C = textscan(fid, '%s, %d, %s, %s, %d, %s, %s, %d, %s, %s, %d, %s, %d, %s, %s, %d, %s, %d, %s, %s, %d');
fclose(fid); n1 = numel(C); % 属性列的个数
n2 = numel(C{1}); % 样本的个数 X = zeros(n1, n2); for i = 1:n1,
if iscell(C{i})
for j = 1:n2,
% A12 ⇒ 2
if i < 10,
d = textscan(C{i}{j}, '%c%c%d');
else
% A103 ⇒ 3
d = textscan(C{i}{j}, '%c%c%c%d');
end
X(i, j) = d{end};
end
else
X(i, :) = C{i};
end
end y = X(end, :);
X(end, :) = []; posX = X(:, y == 1); % 700
negX = X(:, y == 2); % 300 trainX = [posX(:, 1:350), negX(:, 1:150)];
trainY = [ones(1, 350), 2*ones(1, 150)]; testX = [posX(:, 351:end), negX(:, 151:end)];
testY = [ones(1, 350), 2*ones(1, 150)]; [trainX, s1] = mapminmax(trainX);
testX = mapminmax('apply', testX, s1);

matlab 格式化文本文件的解析的更多相关文章

  1. MATLAB对于文本文件(txt)数据读取的技巧总结(经典中的经典)

    振动论坛原版主eight的经典贴http://www.chinavib.com/thread-45622-1-1.html MATLAB对于文本文件(txt)进行数据读取的技巧总结(经典中的经典)由于 ...

  2. MATLAB格式化输出控制 分类: 数学 2015-07-31 23:01 3人阅读 评论(0) 收藏

    MATLAB格式化输出控制 format 默认格式 format short 5字长定点数 format long 15字长定点数 format short e 5字长浮点数 format long ...

  3. kNN(从文本文件中解析数据)

    # 准备数据:从文本文件中解析数据# 在kNN.py中创建名为file2matrix的函数,处理输入格式问题# 该函数的输入为文件名字符串,输出为训练样本矩阵和类标签向量# 将文本记录到转换Numpy ...

  4. matlab中文本文件与图像转化

    一  将图片转化为txt文本文件 a=imread('picture.bmp');   //读取picture.bmp图片 b=rgb2gray(a);                 //由rgb图 ...

  5. Matlab中sortrows函数解析

    一.问题来源 返回检索到的数据(按相关度排序)在原始数据中的索引. 二.问题解析 x = [1 4 3 5; 1 3 2 6]:sortrows(x)其结果是按照row来排列,默认首先排第一列,1和1 ...

  6. Matlab量化函数quantiz解析

    在Matlab里,有一个量化函数quantiz,其函数形式有以下三种: 输入变量: sig代表的是原始信号; codebook代表的是量化值的集合; partition是分割向量,代表对量化范围分割等 ...

  7. MATLAB格式化输出控制

    format 默认格式 format short 5字长定点数 format long 15字长定点数 format short e 5字长浮点数 format long e 15字长浮点数 form ...

  8. Matlab中导入文本文件中的数据 矩阵合并 以及C++中删除文件操作

    今天用到了Matlab读取文本文件中按照一定格式存储好的数据,然后进行后续的分析计算等,因此涉及到Matlab的文件读取,记录在这里,供以后查阅: fid = fopen('train.set', ' ...

  9. Java基础进阶:时间类要点摘要,时间Date类实现格式化与解析源码实现详解,LocalDateTime时间类格式化与解析源码实现详解,Period,Duration获取时间间隔与源码实现,程序异常解析与处理方式

    要点摘要 课堂笔记 日期相关 JDK7 日期类-Date 概述 表示一个时间点对象,这个时间点是以1970年1月1日为参考点; 作用 可以通过该类的对象,表示一个时间,并面向对象操作时间; 构造方法 ...

随机推荐

  1. HttpClient FormUrlEncodedContent System.UriFormatException: 无效的 URI: URI 字符串太长问题解决方案

    1.问题描述: HttpClint 使用FormUrlEncodedContent 调用接口时 报错 System.UriFormatException: 无效的 URI: URI 字符串太长: 2. ...

  2. Access WMI via Python from Linux

    You can use Impacket (https://github.com/CoreSecurity/impacket) that has WMI implemented in Python. ...

  3. RISC-V工具链环境(基于Debian/Linux操作系统)

    RISC-V工具链环境(基于Debian/Linux操作系统) 提要 Debian/Linux虚拟机导入 启动虚拟机 SiFive/Nuclei SDK运行指南 Debian/Linux虚拟机存储位置 ...

  4. [Nuxt] Build a Navigation Component in Vue.js and Use in a Nuxt Layout

    You can isolate parts of templates you want to re-use into components, but you can also reuse those ...

  5. LoaderManager使用具体解释(一)---没有Loader之前的世界

    来源: http://www.androiddesignpatterns.com/2012/07/loaders-and-loadermanager-background.html 感谢作者Alex ...

  6. 26、从零写UVC驱动之分析描述符

    指令:lsusb 可以查看usb设备的描述符信息,当然lsusb指令要带一些参数 一个usb设备有多个config配置+设备描述符,一个config有多个接口和association.config描述 ...

  7. Mac OS X Kernel Basic User Credentials

    User Credentials In order to understand security in OS X, it is important to understand that there a ...

  8. HtmlParser基础教程 分类: C_OHTERS 2014-05-22 11:33 1649人阅读 评论(1) 收藏

    1.相关资料 官方文档:http://htmlparser.sourceforge.net/samples.html API:http://htmlparser.sourceforge.net/jav ...

  9. [tmux] Handle history in tmux sessions

    In this lesson, we'll look at how to manage your history between tmux sessions, and ensure that your ...

  10. java判断字符串是否为数字

    我们在做安卓开发中,一定会遇到判断某字符串是否是数字的问题,本文使用正则表达式可以很方便的判断出来,希望本文对安卓开发者有所帮助.   1 public boolean isNumeric(Strin ...