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

lalianhaizai 2016-01-07 10:20:34
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个列向量的组合。。麻烦大神赐教。。
...全文
141 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

3,423

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 其他开发语言
社区管理员
  • 其他开发语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧