一个关于matlab的问题:有几列数据,如何构造矩阵

lalianhaizai lalianhaizai 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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个列向量的组合。。麻烦大神赐教。。
...全文
评论
收藏 已收藏
分享
返回顶部
lalianhaizai
其他开发语言 3,425 成员 15,624 内容