Extracting all possible vectors from a big vector
Show older comments
Hi guys,
İ want to expalin with an example. Let's say i have a vector [1 2 3 4] i want to extract these [1] [2] [3] [4] [1 2] [1 3] [1 4] [2 3] [2 4] [3 4] [1 2 3] [1 2 4] [1 3 4] [2 3 4] [1 2 3 4] i found a way to do that but the problem is that they are not vectors.
How can i do that?
I know that [2 3] and [3 2] are different vectors but order is not important.
v=[1 2 3 4];
b=length(v);
i=1;
while i<=b
a = uint16(v);
c = nchoosek(a,uint16(i));
disp(c)
i=i+1;
end
2 Comments
Image Analyst
on 12 Jun 2021
Why do you want to do this? What is the use case? The number of output vectors would blow up incredibly fast for more than a length of a few. Like if you had a vector that was hundreds long, it would be impractical.
Mehmet Fatih
on 12 Jun 2021
Accepted Answer
More Answers (1)
SALAH ALRABEEI
on 12 Jun 2021
Edited: SALAH ALRABEEI
on 12 Jun 2021
0 votes
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!