how to plot graph as file attached.

조회 수: 10 (최근 30일)
mohd akmal masud
mohd akmal masud 2024년 12월 11일
답변: Mathieu NOE 2024년 12월 11일
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')

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by