ERROR - Error using zajimava_uloha (line 7) Not enough input arguments. Why?

function pravd = zajimava_uloha(n)
% pravd = zajimava_uloha(n)
%
% vypocte pravdepodobnost toho, ze kdyz nahodne zamichate prirozena
% cisla 1 az n, nezustane ani jedno cislo na sve puvodni pozici
if n <= 0 , n - floor(n) > eps
error('n neni prirozene cislo')
end
perm = permutace(n); % generuje vsechna mozna usporadani n cisel
pocet_perm=size(perm,1); % pocet vsech moznych usporadani n cisel
for i=1:pocet_perm
pom(i,:)=[1:n];
end
P=(pom==perm);
pom2=sum(P,2);
pom2=~pom2;
suma=sum(pom2); % pocet vsech usporadani, u kterych neni ani jedno cislo na svem puvodnim miste
pravd=suma/pocet_perm;
disp(['Pravdepodobnost: ', num2str(pravd)])
% konec

1 件のコメント

Daniel Shub
Daniel Shub 2012 年 4 月 9 日
Please format the code properly. If you could point out line 7 that would also be help. Finally provide the entire error stack.

回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 4 月 9 日

0 投票

How are you calling zajimava_uloha? If you are just using the green "play" button, n the lone input argument will be undefined and you will see this error.
To run this function properly, call it with one input argument, maybe:
zajimava_uloha(pi)

この質問は閉じられています。

タグ

質問済み:

2012 年 4 月 9 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by