一个关于matlab的问题:有几列数据,如何构造矩阵
function [matrix, tokenlist, category] = readMatrix(filename)
fid = fopen(filename);
headerline = fgetl(fid);
rowscols = fscanf(fid, '%d %d\n', 2);
tokenlist = fgetl(fid);
% Document word matrix
% Each row represents a document (mail)
% Each column represents a distinct token
% The (i,j)-th element represents the number of times token j appeared in
% document i
matrix = sparse(1, 1, 0, rowscols(2), rowscols(1)); % the transpose!
% Vector containing the categories corresponding to each row in the
% document word matrix
% The i-th component is 1 if the i-th document (row) in the document word
% matrix is SPAM, and 0 otherwise.
category = matrix(rowscols(1));
%Read in the matrix and the categories
for m = 1:rowscols(1) % as many rows as number of documents
line = fgetl(fid);
nums = sscanf(line, '%d');
category(m) = nums(1);
matrix(XXXXXX) = nums(2:end);
end
matrix = matrix'; % flip it back
fclose(fid);
filename是一个简单的数据集,内容如下:
DOC_WORD_MATRIX_TRAIN
5 5
abil absolut abus access accid
0 1 1 1 0 0
1 1 0 1 0 1
0 0 0 1 1 1
0 0 1 0 0 1
0 1 1 1 0 1
对于代码最后的for循环,每次循环完成后我会得到一个列向量
第一次得到一个列向量1 1 1 0 0,第二次得到一个列向量b=1 0 1 0 1,第三次得到一个列向量 c=0 0 1 1 1,5次循环完成后,得到5个列向量。
问题是如何编写红色部分才能使最后的矩阵式这5个列向量的组合。。麻烦大神赐教。。
fid = fopen(filename);
headerline = fgetl(fid);
rowscols = fscanf(fid, '%d %d\n', 2);
tokenlist = fgetl(fid);
% Document word matrix
% Each row represents a document (mail)
% Each column represents a distinct token
% The (i,j)-th element represents the number of times token j appeared in
% document i
matrix = sparse(1, 1, 0, rowscols(2), rowscols(1)); % the transpose!
% Vector containing the categories corresponding to each row in the
% document word matrix
% The i-th component is 1 if the i-th document (row) in the document word
% matrix is SPAM, and 0 otherwise.
category = matrix(rowscols(1));
%Read in the matrix and the categories
for m = 1:rowscols(1) % as many rows as number of documents
line = fgetl(fid);
nums = sscanf(line, '%d');
category(m) = nums(1);
matrix(XXXXXX) = nums(2:end);
end
matrix = matrix'; % flip it back
fclose(fid);
filename是一个简单的数据集,内容如下:
DOC_WORD_MATRIX_TRAIN
5 5
abil absolut abus access accid
0 1 1 1 0 0
1 1 0 1 0 1
0 0 0 1 1 1
0 0 1 0 0 1
0 1 1 1 0 1
对于代码最后的for循环,每次循环完成后我会得到一个列向量
第一次得到一个列向量1 1 1 0 0,第二次得到一个列向量b=1 0 1 0 1,第三次得到一个列向量 c=0 0 1 1 1,5次循环完成后,得到5个列向量。
问题是如何编写红色部分才能使最后的矩阵式这5个列向量的组合。。麻烦大神赐教。。
...全文
相关推荐
MATLAB 特殊矩阵构造
学习并熟练掌握这些特殊矩阵的构造方法,对于提升MATLAB编程效率和解决实际问题的能力至关重要。
ldpc的编码方法采用matlab构造校验矩阵
**设计校验矩阵**:可以选择现成的、已被证明具有良好性能的预定义码,或者自定义一个。自定义时,可以使用随机生成的方法,或者基于图论中的 Tanner 图构造。
QC_LDPC 校验矩阵构造函数matlab
总之,"QC_LDPC校验矩阵构造函数matlab"是一个关于使用MATLAB构建和分析QC_LDPC码的课题,涉及到编码理论、线性代数和算法实现等多个方面,对于理解LDPC码的工作原理和提升数据传输质量有重要价值
MATLAB 以矩阵形式保存数据
**版本兼容性**:需要注意的是,不同版本的MATLAB可能不完全兼容保存的数据格式。尽量确保在同一版本或兼容版本之间进行保存和加载操作,以避免可能出现的问题。
MATLAB-对矩阵进行赋值时的维度问题
在MATLAB编程中,矩阵赋值是一个常见的操作,但如果不注意矩阵的维度和索引,可能会遇到一些陷阱。本文将详细解析在MATLAB中对矩阵进行赋值时应注意的维度问题。


其他开发语言
