how to read specified letters from ascii file

조회 수: 5 (최근 30일)
narimen boucenna
narimen boucenna 2020년 7월 2일
댓글: narimen boucenna 2020년 7월 3일
i want prgrm that reads ascii file but only the letters 'a' to 'z' using ascii code 97:122 and i want to put those letters in new file and save them
  댓글 수: 7
narimen boucenna
narimen boucenna 2020년 7월 2일
i did actually nothing that i could find usefull
Rik
Rik 2020년 7월 2일
I just googled 'read ascii text file to char array matlab'. The top 3 results all suggest the fileread function.

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2020년 7월 2일
inputFileName = 'C:\input.txt';
outputFileName = 'C:\output.txt';
fileID = fopen(inputFileName,'r');
A = fread(fileID,'*char');
fclose(fileID);
A = A(A >= 97 & A <= 122); % using logical indexing to keep only 'a' to 'z'
fileID = fopen(outputFileName,'w');
fprintf(fileID,'%s',A);
fclose(fileID);
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 7월 2일
We recommend against providing complete solutions for homework problems.
narimen boucenna
narimen boucenna 2020년 7월 3일
thnx for the progrm it really helped me when i opend the new file i found what i was looking for

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 7월 2일
Try this:
% chr = fileread('test1.m') % Whatever file you want to read in.
chr = '123456abcdef ABCDEF 789.' % String for testing.
TF = isstrprop(chr,'alpha')
newChr = chr(TF)
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 7월 2일
This will grab upper case as well as lower case.
narimen boucenna
narimen boucenna 2020년 7월 3일
unfortunately it didnt work the result was
abcdefABCDEF
and its not what i was looking for but thnx for the help i really appreciate it

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by