# Problem of mathematics and programming

2 Ansichten (letzte 30 Tage)
Aaros am 31 Jan. 2013
Suppose I have an array stored 50 data, data are just '0' and '1' The probability of occurrence of '0' is 0.1 The probability of occurrence of '1' is 0.9
So there are five '0' and forty-five '1' and suppose the five '0' are appeared first.
The sequence is :{0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,.....,1}
I want to find out all the sequenes which the '0' are located at different position.
ie: the five '0' are placed at every different locations
Can matlab function solve this question? how to implement to solve this?
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Youssef Khmou am 31 Jan. 2013
[value,index]=find(VECTOR==0)

Melden Sie sich an, um zu kommentieren.

### Antworten (5)

Walter Roberson am 31 Jan. 2013
Are you looking for the permutations of the array? There would be (50!) / ((45!)*(5!)) = 2118760 of them. What are you going to do with them after you find them all?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Matt J am 31 Jan. 2013
Bearbeitet: Matt J am 31 Jan. 2013
x=[0 0 0 0 0, ones(1,45)];
idx=nchoosek(1:50,5);
rows=repmat((1:size(idx,1)).',[1,5]);
result = ~full(sparse(rows,idx,true));
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Jonathan Epperl am 31 Jan. 2013
Like Walter said, what you are ultimately looking for are all the combinations you obtain from drawing 5 out of 50 without replacement, so nchoosek(50,5). Matlab will give you a matrix where each row is one combination
M = nchoosek(1:50,5);
You'll get your 0s and 1s then by (and I'm sure there are better ways):
M = nchoosek(1:50,5);
Z = ones(10,size(M,1));
MM = M + (0:size(M,1)-1)'*10*ones(1,size(M,2));
Z(MM)=0;
imagesc(Z')
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Aaros am 31 Jan. 2013
i need to use those sequences to be a fault vector.
also, the probability will be changed, the number of '0' will increase or decrease
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Youssef Khmou am 31 Jan. 2013
Bearbeitet: Youssef Khmou am 31 Jan. 2013
V=[0 0 0 0 0 1 1 1 1 1];
to find the positions you try :
[value,index]=find(V==0)
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Elementary Math finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by