how to plot graph as file attached.

10 views (last 30 days)
mohd akmal masud
mohd akmal masud on 11 Dec 2024
Answered: Mathieu NOE on 11 Dec 2024
Dear all,
I have file as attached. Anyone can help me how to plot the graph from the file as attached.
  2 Comments
Epsilon
Epsilon on 11 Dec 2024
Hi mohd, Can you please elaborate what kind of a plot are you looking for.
mohd akmal masud
mohd akmal masud on 11 Dec 2024
Dear @Epsilon.
Actually my origionally data come from pointclass3.lmf file as attached. Then to open pointclass3.lmf, I used the coding below:
fid = fopen('pointclass3.lmf');
stream = fread(fid,inf,'*uint8');
fclose(fid);
recordlen = 20 + 8 + 1; % 10x16b, 1x64b, 1x8b
headerlen = mod(numel(stream),recordlen) % is there a header??
header = stream(1:headerlen);
data = reshape(stream(headerlen+1:end),recordlen,[]);
% the 16b fields
xyz0 = typecast(reshape(data(1:6,:),[],1),'uint16');
xyz0 = reshape(xyz0,3,[]).';
xyzphantom = typecast(reshape(data(7:12,:),[],1),'uint16');
xyzphantom = reshape(xyzphantom,3,[]).';
xyzcrystal = typecast(reshape(data(13:18,:),[],1),'uint16');
xyzcrystal = reshape(xyzcrystal,3,[]).';
energy = typecast(reshape(data(19:20,:),[],1),'uint16');
% the double float field
photonweight = typecast(reshape(data(21:28,:),[],1),'double');
% the 8b field
scatterorder = typecast(reshape(data(29,:),[],1),'uint8');
Then, there severals data outputs in workspace like picture below.
Then I want to plot the graph "energy" based on the energy output as in workspace. Maybe you can help me to plot based on the header file pointlmf.h00
Actually, the pointclass3.lmf file description as below:

Sign in to comment.

Answers (1)

Mathieu NOE
Mathieu NOE on 11 Dec 2024
hello
you can read your header file with any matlab function that read ascii / txt files . Here I opted for readlines . Still you have to say what we want to do now with the header
then you can use your code to extract the data, you only need to apply the sacling factor correction to have your plot with the right data (in keV)
%% read header file
header = readlines('pointlmf.h00');
% and now ? ...
%% open lmf file
fid = fopen('pointclass3.lmf');
stream = fread(fid,inf,'*uint8');
fclose(fid);
recordlen = 20 + 8 + 1; % 10x16b, 1x64b, 1x8b
headerlen = mod(numel(stream),recordlen) % is there a header??
header = stream(1:headerlen);
data = reshape(stream(headerlen+1:end),recordlen,[]);
% the 16b fields
xyz0 = typecast(reshape(data(1:6,:),[],1),'uint16');
xyz0 = reshape(xyz0,3,[]).';
xyzphantom = typecast(reshape(data(7:12,:),[],1),'uint16');
xyzphantom = reshape(xyzphantom,3,[]).';
xyzcrystal = typecast(reshape(data(13:18,:),[],1),'uint16');
xyzcrystal = reshape(xyzcrystal,3,[]).';
energy = typecast(reshape(data(19:20,:),[],1),'uint16');
% the double float field
photonweight = typecast(reshape(data(21:28,:),[],1),'double');
% the 8b field
scatterorder = typecast(reshape(data(29,:),[],1),'uint8');
%% plot energy
energy = double(energy/10); % apply energy scaling factor = 10, then convert to double (optionnal) ; now units are keV
plot(energy);
ylabel('keV')

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!