How can I fix this error?

10 ビュー (過去 30 日間)
Zaid Alhemedi
Zaid Alhemedi 2023 年 8 月 5 日
編集済み: VBBV 2023 年 8 月 5 日
I followed the written code literally but it still says there is an error in line 4 y = finitepmf(s,p,x);
Therefore, I could not have the answer
>> shipweightpmf( [2 2.5 6] )'
ans = 0.1500 0 0.1000
that is written in the second box of the example picture that it has been attached.
Any hints or details explaination are highly appreciated.
function y = shipweightpmf(x)
s = (1:8)';
p = [0.15*ones(4,1); 0.1*ones(4,1)];
y = finitepmf(s,p,x);

採用された回答

VBBV
VBBV 2023 年 8 月 5 日
shipweightpmf( [2 2.5 6] )'
ans = 1×3
0.1500 0 0.1000
function y = shipweightpmf(x)
s = (1:8)';
p = [0.15*ones(4,1); 0.1*ones(4,1)];
y = finitepmf(s,p,x);
end
function pmf=finitepmf(sx,px,x)
% finite random variable X:
% vector sx of sample space
% elements {sx(1),sx(2), ...}
% vector px of probabilities
% px(i)=P[X=sx(i)]
% Output is the vector
% pmf: pmf(i)=P[X=x(i)]
pmf=zeros(size(x(:)));
for i=1:length(x)
pmf(i)= sum(px(find(sx==x(i))));
end
end
  1 件のコメント
VBBV
VBBV 2023 年 8 月 5 日
編集済み: VBBV 2023 年 8 月 5 日
Use these links below for more information about that function (probability mass function)
https://in.mathworks.com/matlabcentral/answers/627263-how-to-find-probability-mass-function

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by