how to plot graph as file attached.

2 次查看(过去 30 天)
Dear all,
I have file as attached. Anyone can help me how to plot the graph from the file as attached.
  2 个评论
Epsilon
Epsilon 2024-12-11
Hi mohd, Can you please elaborate what kind of a plot are you looking for.
mohd akmal masud
mohd akmal masud 2024-12-11
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:

请先登录,再进行评论。

回答(1 个)

Mathieu NOE
Mathieu NOE 2024-12-11
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')

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by