how can print every word in new line but skip printing if word is repeating..this is a sorted list of words
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
Respuestas (1)
Jan
el 27 de Jun. de 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 comentarios
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!