how can print every word in new line but skip printing if word is repeating..this is a sorted list of words
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
close all;clear all;clc%creatiing word list with repeatation fid1=fopen('textfile.txt','r'); fid2=fopen('wordslist','w'); while ~ feof(fid1) new_line = fgetl(fid1); a=new_line; b=strsplit(a);c=[b(end) b]; c=cat(2,b(end),b); f=cat(2,c(1),(c(3:end))) fprintf(fid2, '%s\n', f{:}) end fclose(fid1); fclose(fid2); I want to sort wordlist and then print again while not print the repeating word. for example if output is like as bar yoyo same bar yoyo bar man i want output like this as bar man same yoyo thanks in advance
Réponses (1)
Jan
le 27 Juin 2018
str = fileread('textfile.txt');
str(ismember(str, sprintf('.,\n\r'))) = ' ';
words = unique(strsplit(str, ' '));
fid = fopen('wordslist', 'w');
if fid == -1
error('Cannot open file for writing');
end
fprintf(fid, '%s\n', words{:});
fclose(fid);
0 commentaires
Voir également
Catégories
En savoir plus sur Standard File Formats dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!