필터 지우기
필터 지우기

Created a class fucntion but I am not able to find output for certain conditions even though the value exists.

조회 수: 1 (최근 30일)
I have attached data file "air.mat"
1st column is energy (MeV)
2nd column is mass attenuation coefficient
calculated 3rd column as Attenuation coefficient
I tried to run the code in command window as follows :-
obj=material("air",0.0012);
AttenuationCoefficient=getAttenuationCoefficient(obj,0.060)
the code is giving out put for all values of energy (MeV) except 0.060,0.061,0.059 MeV
classdef material
properties (Access=public)
name
density
data_new
energy
mass_attenuation_coefficent
end
methods
function obj=material(name,density)
obj.name=name;
obj.density=density;
filetype=".mat";
text=strcat(obj.name,filetype);
data_1=load(text);
T = table(data_1.data(:,1),data_1.data(:,2),'VariableNames',{'Energy','mass_attentuation_coefficient'});
G = groupsummary(T,"Energy","mean");
a=G.Energy(1,1);
b=G.Energy(end,1);
c=a:a/10:b;
z=interpn(G.Energy,G.mean_mass_attentuation_coefficient,c,'spline');
obj.data_new=[c',z',c'.*z'];
obj.energy=obj.data_new(:,1);
obj.mass_attenuation_coefficent=obj.data_new(:,2);
end
end
methods
function AttenuationCoefficient=getAttenuationCoefficient(obj,energy)
row = obj.data_new(:,1) == energy;
AttenuationCoefficient=obj.data_new(row,3);
end
end
end

채택된 답변

Matt J
Matt J 2022년 2월 14일
편집: Matt J 2022년 2월 14일
Tsk, tsk. You should know better than to test for exact equality with floating point values.
>> obj.energy(591)
ans =
0.0600
>> obj.energy(591)-0.060
ans =
6.9389e-18
Here is how I would implement the method,
function AttenuationCoefficient=getAttenuationCoefficient(obj,energy)
AttenuationCoefficient=interp1( obj.data_new(:,1), obj.data_new(:,3), energy);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by