Why am I getting an error message on my code?
2 views (last 30 days)
Show older comments
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 Comments
Answers (2)
VBBV
on 23 Mar 2023
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 Comment
VBBV
on 23 Mar 2023
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
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!