プログラムの目的は、ファイルを調べて文字列を探し、文字列が含まれていた行でその文字列のすべてのインスタンスを吐き出すことです。
ファイルを検索して見つけることができましたが、それらをすべて格納できる配列または何かに入れることができませんでした。現時点では、最後のインスタンスが表示されます。最初のインスタンスを見つけるために、8 行目と 9 行目の間に簡単に 1 つの区切りを入れることができます。
問題の文字列を含むすべての行を保存する方法を誰かが知っていれば、それは大きな助けになります。
fid = fopen('....... file directory....')
prompt = 'What string are you searching for? ';
str = input(prompt,'s');
i=0;
for j=1:10000;
tline = fgetl(fid); %Returns next line of specified file
counter = counter + 1; %Counts the next line
if ischar(tline); %Checks if the line is an array
U=strfind(tline,str); %Sets U to be 1 if strfind finds the string in line tline
if isfinite(U) == 1
what = tline; %This is where I want to set the array positions equal to whatever tline is at that time, then move onto the next i and search for the next tline.
i=i+1;
end
end
end