Produce a function to run each element of column vector through an equation to produce a column vector of outputs
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello,
I have a set a data in a single column vector.
I would like to run each value through the equation that is attached as a screen shot.
In a function file I have created the following function:
function P = erf(A)
%Function to produce 'P'
% 'P' is the error function of the rpec values (Input Array 'A')
%Define Mean of background
Ubg = 0.3991
%Define SD of rpec ratios
Orpec = 0.4580
%Define SD of background
Obg = 0.3751
%Define SD of specific
Osp = 0.2963
%compute SD of rpec squared + SD of bg squared + SD of sp squared
inter1 = Orpec^2 + Obg^2 + Osp^2
%compute 2 times inter1
inter2 = 2*inter1
%compute square root of inter2
SRI2 = sqrt(inter2)
%compute rpec - Ubg
inter3 = A-Ubg
%compute absolute values of inter3
ABI3 = abs(inter3)
%compute P
P = ABI3/SRI2
end
I then call the funciton in the command window and select my input array which is 'H' by:
erf(H)
The output array that is created does not have the values that I would expect.
Could anyone tell me where I am going wrong?
Sorry if this is a silly question im new to matlab and rusty on my maths!
Any help would be greatly appreciated!
Thanks x
댓글 수: 5
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!