how can print every word in new line but skip printing if word is repeating..this is a sorted list of words

5 ビュー (過去 30 日間)
muaz shaikh
muaz shaikh 2018 年 6 月 27 日
回答済み: Jan 2018 年 6 月 27 日
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

回答 (1 件)

Jan
Jan 2018 年 6 月 27 日
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);

カテゴリ

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