how to extract matrix column and make new matrixes from the extracted column?

조회 수: 1 (최근 30일)
eri
eri 2011년 11월 1일
how to extract matrix column and make new matrixes from the extracted column? if you name the column a, b, and c then i want to create matrixes which consist of
a
b
c
ab
ac
bc
abc

답변 (2개)

Image Analyst
Image Analyst 2011년 11월 1일
a = fullMatrix(:, colA); % colA is whatever column number "a" is in. It's an integer.
b = fullMatrix(:, colB);
c = fullMatrix(:, colC);
ab = fullMatrix(:, colAB);
ac = fullMatrix(:, colAC); % etc.
% Concatenate
newColVector = [a;b;c;ab;ac;bc;abc]
  댓글 수: 2
eri
eri 2011년 11월 1일
i am not in front of my computer right now and there is no matlab in the computer i currently use, so i cannot try it right away
but i still have questions:
1. you wrote 'fullMatrix' is this a function in matlab or i should enter the matrix
2. it seems that your answer requires me to write a function for each combination, while actually i am going to work with a big matrix(more than 50 columns), and there would be {(2^n)-1} combination, so i would like you and other people here to give solution how to make program that will automatically create those combination
Daniel Shub
Daniel Shub 2011년 11월 1일
@eri, do you realize how big of a number 2^50 is?

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 11월 1일
Where YourMatrix is your existing matrix with all columns, and the number of columns is at most 52 (or is it 53?)
ncols = size(YourMatrix,2);
numoutputs = 2^ncols;
TheOutputs = cell(numoutputs,1);
for K = 1 : numoutputs
TheOutputs{K} = YourMatrix(:,dec2bin(K-1,ncols) == '1');
end
If you are enthusiastic about the leading columns being chosen first, then you can fliplr() the result of the comparison.
Do not be surprised if at the creation of TheOutputs you get an error about the size of the cell array being too big to handle. If that happens, you can comment out that line as it is just an optimization.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by