How do I access reference text file? Low Level I/O

Hello, I am trying to do this "The reference filenames will always be formatted as ‘<input1>_#.txt’. For example, if the first input of the function were ‘hpLastPage’ and the current cipher line were 3-23-8-4, you would be looking in the file called ‘hpLastPage_3.txt’."
fh2 = fopen('cipher_1.txt')
line2 = fgetl(fh2);
Line2 = 1-21-9-1;
[a line2] = strtok(line2, '-');
a = 1
line2 = -21-9-1
[fileName, ~] = strtok('hpLastPage')
tiger = [fileName, '_kat.txt'];
This is what I did and for tiger I got
tiger = 'hpLastPage_a.txt'
How do I get hpLastPage_1.txt rather than hpLastPage_a.txt.
Thank you.

 채택된 답변

per isakson
per isakson 2015년 2월 24일
matFileName = sprintf('mat%d.mat', k);

댓글 수: 3

Kratos
Kratos 2015년 2월 24일
Thanks for the help. I have one more question. How do I extract a specific string from a text file. I would like to read the 21 line on the text file and print it. I used textscan and textread but I did't get what I wanted.
for jj = 1 : 21
str = fgetl(fh2)
end
is one way.
Kratos
Kratos 2015년 2월 24일
Thanks for the help.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

질문:

2015년 2월 24일

댓글:

2015년 2월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by