how do i save unique words from a cell to a text file?

1 回表示 (過去 30 日間)
Zubier  Abdullah
Zubier Abdullah 2017 年 8 月 12 日
コメント済み: per isakson 2017 年 8 月 13 日
Hey guys
I am trying to go through a number of text files and I want to find all of the unique words and save them in a different text file (dictionary.txt) . After doing that, I want to compare all of the original documents and replace the words with the position of the words from dictionary.txt. Can anyone help me find some code examples that I can follow?
Say - dictionary contains 'Goat', 'Tommy', 'Bag', 'is', 'wild', 'a' Txt file 1 has - Tommy is a wild goat would become 24651
This is the code I have written so far. I cannot save the file.
clc
clear all
close all
fid = fopen('test.txt');
fgetl(fid);fgetl(fid); %we are gettin rid of the first 2 lines of the thing using fgetl
words = textscan(fid,'%s'); %we are text scanning the words from the document
status = fclose(fid)
lower(words{1,1}) %we are making all of the words lowercase
%here we are getting rid of all of the words which are one letter
for i = 1:numel(words{1,1})
if size(words{1,1}{i,1}, 2) == 1
words{1,1}{i,1} = ' ';
end
end
%%Get rid of all Non words(Numbers)
for i=1:numel(words{1,1})
ind = find(isstrprop(words{1,1}{i,1}, 'digit') == 1);
words{1,1}{i,1}(ind)=[];
end
for i=1:numel(words{1,1})
ind = find(isstrprop(words{1,1}{i,1}, 'alphanum') == 0);
words{1,1}{i,1}(ind)=[];
end
mkdir('output')
dictionary = fopen('dict.txt','w')
[words,frequency,position] = unique(words{1,1})
words = lower(words)
fid2 = fopen('dict.txt','w')
fwrite(fid2,words)
  1 件のコメント
per isakson
per isakson 2017 年 8 月 13 日
Do all of the text files fit in a fraction of the memory (RAM)?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 8 月 12 日
fprintf(fid2, '%s\n', words{:});
fclose(fid2)

カテゴリ

Help Center および File ExchangeStandard File Formats についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by