MATLAB: How to obtain the number of lines starting with a given string from an external text file and save the numeric value of variables of those lines

MATLAB

Hello,
I have an external text file. A part of the text file (example) is shown below:
/AA
/BB
/CC
DRL=1
DRL=2
DRL=4
/XX
/YY
/ZZ
How can I :
-Obtain the number of lines starting with "DRL" and save it to the variable pnumber. In this case pnumber=3
-save the value of those variables in the vector A, in my example A =[1;2;4]
I thank you in advance for any help,
Best regards,
Hugo

Best Answer

Another approach:
data = readtable('test.txt'); % test.txt contains the given text
drl_count = sum(strcmp(data.Var1,'DRL'));
drl_value = data.Var2(strcmp(data.Var1,'DRL'));
>> drl_count =
3
drl_value =
1
2
4