How to read .bnn.lis file (ascii file) for the specific data

11 views (last 30 days)
Dear Experts,
I want to read the values inside orange line as an array.
file name is " SCINTILLAORS STACK WITH CHAMBER-1_21.bnn.lis " which looks like in the image (file is attached which I can open in with .txt format as i couldn't attach the original .bnn.lis file).
I tried the following method but it is not giving the desired terms
filename='SCINTILLAORS STACK WITH CHAMBER-1_21.bnn.lis';
fileid=fopen(filename);
c=textscan(fileid,'%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f');
fclose(fileid);
whos c
Please, help me take out the values inside the orange line
Thank you

Accepted Answer

Mathieu NOE
Mathieu NOE on 26 Aug 2022
hello
this is one possibility :
lines = readlines('SCINTILLAORS STACK WITH CHAMBER-1_21.txt');
%% main code
nn = find(contains(lines,'accurate deposition along the tracks requested')); % find the line number of this text
lines_to_read = 2; % read the 2 lines after line containing above text
for ck = 1:lines_to_read
tmp = (str2double(split(lines(nn+ck))))';
tmp(isnan(tmp)) = []; % remove NaNs
out{ck,1} = tmp; % store in cell array
end
% export to txt
writecell(out,'output.txt',"Delimiter","\t");
  5 Comments
SHUBHAM AGARWAL
SHUBHAM AGARWAL on 26 Aug 2022
Dear Mathieu,
Thank you very much. You are a great help and teacher.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!