Why am I getting an error message on my code?
2 次查看(过去 30 天)
显示 更早的评论
function [estPiAve, estPiStD] = estPiStats(numThrows,numTrials)
estPiValues = zeros([numTrials 1]);
% populate the estPiValues vector
for i = 1:numTrials
estPiValues(i) = estPi(numThrows);
end
estPiAve = mean(estPiValues);
estPiStD = std(estPiValues);
plot(estPiValues,'o')
hold on
plot([1, numTrials], pi^[-1, 1],'k');
plot([1, numTrials], (estPiAve+1.96^estPiStD)^[-1, 1],'--k');
plot([1, numTrials], (estPiAve-1.96^estPiStD)^[-1, 1]),'--k';
hold off
end
Not enough input arguments.
Error in estPiStats (line 3)
estPiValues = zeros([numTrials 1]);
0 个评论
回答(2 个)
VBBV
2023-3-23
numThrows = 10;
numTrials = 30;
[estPiAve, estPiStD] = estPiStats(numThrows,numTrials) % provide all input arguments when calling function
function [estPiAve, estPiStD] = estPiStats(numThrows,numTrials)
estPiValues = zeros([numTrials 1]);
% populate the estPiValues vector
for i = 1:numTrials
estPiValues(i) = rand(1); %estPi(numThrows);
end
estPiAve = mean(estPiValues);
estPiStD = std(estPiValues);
plot(estPiValues,'o')
hold on
plot([1, numTrials], pi.^[-1, 1],'k');
plot([1, numTrials], (estPiAve+1.96^estPiStD).^[-1, 1],'--k');
plot([1, numTrials], (estPiAve-1.96^estPiStD).^[-1, 1]),'--k';
hold off
end
1 个评论
VBBV
2023-3-23
if you dont provide all input arguments to the function, then it results in such error
numThrows = 10;
numTrials = 30;
[estPiAve, estPiStD] = estPiStats(numThrows) % if you dont provide enough input arguments it will throw such error
function [estPiAve, estPiStD] = estPiStats(numThrows,numTrials)
estPiValues = zeros([numTrials 1]);
% populate the estPiValues vector
for i = 1:numTrials
estPiValues(i) = rand(1); %estPi(numThrows);
end
estPiAve = mean(estPiValues);
estPiStD = std(estPiValues);
plot(estPiValues,'o')
hold on
plot([1, numTrials], pi.^[-1, 1],'k');
plot([1, numTrials], (estPiAve+1.96^estPiStD).^[-1, 1],'--k');
plot([1, numTrials], (estPiAve-1.96^estPiStD).^[-1, 1]),'--k';
hold off
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!