how to read specified letters from ascii file
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
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
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
2020 年 7 月 2 日
We recommend against providing complete solutions for homework problems.
その他の回答 (1 件)
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!