MATLAB: Compare .txt to a string.

comparestringtxt

How can you compare each line of a .txt file to a string?

Best Answer

you can use the function strcmp(). which will compare two strings.
to expand a bit more you can look up the function fgetl() which has the example
fid=fopen('fgetl.m');
while 1
tline = fgetl(fid);
if ~ischar(tline), break, end
disp(tline)
end
fclose(fid);
and then using strcmp() you'd insert in the for-loop
same = strcmp(tline,'comparisonstrings');
i'll leave it to you to figure out how you want to save/store the results.