how to plot graph as file attached.

3 ビュー (過去 30 日間)
mohd akmal masud
mohd akmal masud 2024 年 12 月 11 日
コメント済み: Mathieu NOE 2025 年 4 月 2 日
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')
  1 件のコメント
Mathieu NOE
Mathieu NOE 2025 年 4 月 2 日
hello again
problem solved ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLighting, 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