# How can I save values in a matrix?

7 views (last 30 days)
mary bakali on 29 May 2015
Answered: Ingrid on 29 May 2015
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 on 29 May 2015
you need to provide an indexing so
y(i)=SimAirplane(a,x);

### Community Treasure Hunt

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

Start Hunting!