how to extract matrix column and make new matrixes from the extracted column?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (2)
Image Analyst
le 1 Nov 2011
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 commentaires
Walter Roberson
le 1 Nov 2011
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.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!