필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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 CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by