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

3 vues (au cours des 30 derniers jours)
Zubier  Abdullah
Zubier Abdullah le 12 Août 2017
Commenté : per isakson le 13 Août 2017
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 commentaire
per isakson
per isakson le 13 Août 2017
Do all of the text files fit in a fraction of the memory (RAM)?

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 12 Août 2017
fprintf(fid2, '%s\n', words{:});
fclose(fid2)

Catégories

En savoir plus sur Standard File Formats dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by