Not enough input arguments

Hi, i need help. When i try to run this line of code,
function [prob, mean_val, one_std, two_std, area] = calcProbs(pdf, a, b, mu1, sigma1, mu2, sigma2)
% Integrate the probability density function over the interval [a, b] to get the probability
prob = integral(pdf, a, b);
An error shows which says,
>> calcProbs(pdf, a, b, mu1, sigma1, mu2, sigma2)
Error using pdf
Requires at least two input arguments.
Im not sure where im going wrong.

6 件のコメント

Stephen23
Stephen23 2023 年 12 月 12 日
calcProbs(pdf, a, b, mu1, sigma1, mu2, sigma2)
What values are you using for PDF, A, B, MU1, SIGMA1, MU2, and SIGMA2 ?
Dyuman Joshi
Dyuman Joshi 2023 年 12 月 12 日
Is pdf a function handle of a single independent variable?
Sumayya
Sumayya 2023 年 12 月 12 日
No values were given, You should not define a specific pdf, but allow the function to work for an arbitrary pdf.
Torsten
Torsten 2023 年 12 月 12 日
編集済み: Torsten 2023 年 12 月 12 日
But if you test the code, you cannot call the function without specific inputs for pdf, a, b, mu1, sigma1, mu2, sigma2. Maybe it was that you just wrote calcProbs(pdf, a, b, mu1, sigma1, mu2, sigma2) in the editor without defining inputs before which caused the error ?
Sumayya
Sumayya 2023 年 12 月 12 日
That makes sense, if i did have the values, would i put it after or before
function [prob, mean_val, one_std, two_std, area] = calcProbs(pdf, a, b, mu1, sigma1, mu2, sigma2)
Torsten
Torsten 2023 年 12 月 12 日
% Script part
pdf = ...
a = ...
b = ...
mu1 = ...
sigma1 = ...
mu2 = ...
sigma2 = ...
[prob, mean_val, one_std, two_std, area] = calcProbs(pdf, a, b, mu1, sigma1, mu2, sigma2)
% function part
function [prob, mean_val, one_std, two_std, area] = calcProbs(pdf, a, b, mu1, sigma1, mu2, sigma2)
...
end

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

回答 (1 件)

Aiswarya
Aiswarya 2023 年 12 月 18 日

0 投票

Hi Sumayya,
I understand that you want to create a function which calculate probabilities based on a probability density function ("pdf") given as input. The error "Error using pdf. Requires at least two input arguments." is because you haven't defined the variables for your inputs before calling the function. So the term 'pdf' refers to the following inbuilt function in MATLAB : https://www.mathworks.com/help/stats/prob.normaldistribution.pdf.html
This function gets invoked when you use the term 'pdf'. The minimum number of arguments for this function is 2 and hence the error.
This can be solved by initializing the variable 'pdf' properly before calling the function 'calcProbs' or a better alternative would be to rename the variable.
Also, you should define your all input arguments in the workspace before calling your function, in order for your function call to work.

カテゴリ

ヘルプ センター および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品

リリース

R2023b

タグ

質問済み:

2023 年 12 月 12 日

回答済み:

2023 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by