I was asked to create a simulation of an airflight, in three steps:(The problem is in the third step, the first two functions work properly. However, I'm including them for better understandment)
Step 1:
function failure= SimEngine(x)
n=rand(1,1);
if (n<x)
failure=true;
else failure=false;
end
end
Step 2:
function crush= SimAirplane(a,x)
m=0;
for i=1:a
A=SimEngine(x);
if (A==1)
m=m+1;
end
end
if (m>(a/2))
crush=true;
else
crush=false;
end
end
So in the third step, I was asked to use the two function above and create a function with three variables.
function y = SimNAirplanes(b,a,x)
y=[];
k=0;
for i=1:1:b
s=SimAirplane(a,x)
if (s==1)
k=k+1;
end
end
end
When using the third function, e.g. SimNAirplane(2,2,0.5) this is displayed:
s=0
s=1
s=0
My question is what command can I use, so that Matlab displays this: y=[0;1;0]?

 채택된 답변

Ingrid
Ingrid 2015년 5월 29일

0 개 추천

you need to provide an indexing so
y(i)=SimAirplane(a,x);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품

태그

질문:

2015년 5월 29일

답변:

2015년 5월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by