필터 지우기
필터 지우기

A question about for loop

조회 수: 2 (최근 30일)
Mnr
Mnr 2014년 12월 22일
답변: Azzi Abdelmalek 2014년 12월 22일
Hello all,
I have a vector p=[.5 .7 .2]; I have a quantity d that is equal to (1-p(1))*(1-p(2))*p(3)+(1-p(1))*p(2)*(1-p(3))+p(1)*(1-p(2))*(1-p(3))
Can anybody tell me how I can use for loop to get d instead of writing the formula of that?
Thanks.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 22일
p=[.5 .7 .2];
idx=nchoosek(1:3,2)
out=0;
for k=1:size(idx,1)
m=setdiff(1:3,idx(k,:));
out=out+p(m)*(1-p(idx(k,1)))*(1-p(idx(k,2)))
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by