Some problem with the sprintf function
조회 수: 1 (최근 30일)
이전 댓글 표시
clear all;
dirc = dir('*.htm');
c=size(dirc);
l2='';
%coun = zeros(1000,877);
for file =1:c
range=(sprinf('A%d',file));
l1 = dirc(file).name;
l3 = strcat(l2,l1);
text = fileread(l3);
text1 = lower(text);
txt = regexprep(text1,'<.*?>| |?|"|-|!|£|$|^|&|*|(|)|{|}|[|]|','');
text_tokenized = regexp (txt, '\W', 'split');
xpr = '<(\w+).*?>.*?</\1>';
ts = sort(text_tokenized);
t=transpose(ts);
[rows,cols] = size(t);
[words, coun, x] = unique(t);
coun=histc(x,1:length(coun));
%xlswrite('tempdata.xls', words, file);
count=coun';
xlswrite('tempdata.xls', count,'Sheet1',range);
end
When I try executing the program, it gives me an Error.
Error in ==> reading_file at 6 rang=(sprinf('A%d',file)); Please Let me know what is wrong.
And also Please help me by giving a snipet to store the values of count and words for all the files. (At the moment, it only displays the value of the last file).
댓글 수: 0
채택된 답변
Walter Roberson
2011년 2월 8일
c = size(dirc)
is an array. You then try to use "for file=1:" that array, which isn't going to work the way you want. You probably want
c = length(dirc)
Also, the command is "sprintf", not "sprinf".
To store for all the files,
[words{k}, coun, x] = unique(t);
count{k} = histc(x,1:length(coun)) .';
xlswrite('tempdata.xls', count{k},'Sheet1',range);
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!