Why am I getting an error message on my code?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
VBBV
am 23 Mär. 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 Kommentar
VBBV
am 23 Mär. 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
Siehe auch
Kategorien
Mehr zu Numeric Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!