Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Undefined function [btrial] or input arguments of type 'double'

조회 수: 1 (최근 30일)
Ella
Ella 2014년 12월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi I get the above error in Matlab. I am trying to test a binomial function. This is the function:
function res = btrial(p)
if rand()<=p,
res = 1;
else
res = 0;
end
end
This is my test:
N = 10;
p = 0.1;
for i = 1:N;
disp(btrial(p));
end
I cannot find the error. Thank you.

답변 (1개)

Image Analyst
Image Analyst 2014년 12월 20일
I made an m-file called test2.m and put all of this into it, and it worked fine:
function test2
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
N = 10;
p = 0.1;
for i = 1:N;
disp(btrial(p));
end
function res = btrial(p)
if rand()<=p,
res = 1;
else
res = 0;
end

태그

Community Treasure Hunt

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

Start Hunting!

Translated by