How can I save values in a matrix?

1 回表示 (過去 30 日間)
mary bakali
mary bakali 2015 年 5 月 29 日
回答済み: Ingrid 2015 年 5 月 29 日
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 日
you need to provide an indexing so
y(i)=SimAirplane(a,x);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by