How to find dependent column vectors of a matrix for a given column vector?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
For example if I have a matrix m where:
m=[1 2 3 4; ...
1 5 3 6; ...
1 7 3 8];
if I put as an input column 1 ,m(:,1), I receive the result:
r=[3 3 3]'
thanks,
1 commentaire
Image Analyst
le 17 Mar 2016
Modifié(e) : Image Analyst
le 17 Mar 2016
I don't understand. If you pass some function column 1 of m, which is [1;1;1], then how are you getting the result of [3,3,3]'??? Does it have something to do with m having 3 rows? So the function I would guess would recognize that [1;1;1] is column 1, and would get, say, foundColumnNumber = 1 (because it found it in column #1), but then do you do something like
r = m(1, foundColumnNumber) * ones(size(m, 1), 1);
where it takes the first element in the found column and replicates it for as many rows as you have???
Réponses (2)
Pavithra Ashok Kumar
le 21 Mar 2016
One of the ways to find this would be to do an element-wise ratio and check if the multiple is constant. The same can also be achieved by using the cross product of the vectors.
for i = 1:ncols
b = A(:,i)./X; %Do element-wise division
if((b(1)*ones(nrows,1)) == b) % check if it is a constant
disp(i); % This would give the indices of the dependent columns
end
end
However, If you could give more information on the use-case, the community might be able to suggest better alternatives. Hope this helps.
0 commentaires
Stephen23
le 21 Mar 2016
Guessing a bit because the question is not totally clear... here is a function that returns the column indices of any columns that are integer multiples of the input column vector:
>> m = [1,2,3,4;1,5,3,6;1,7,3,8];
>> fun = @(c)all(~diff(bsxfun(@rdivide,m,c)));ú
>> fun([1;1;1])
ans =
1 0 1 0
>> fun([2;3;4])
ans =
0 0 0 1
>> fun([2;5;7])
ans =
0 1 0 0
And you can extract those columns by using these indices:
>> m(:,fun([2;3;4]))
ans =
4
6
8
>> m(:,fun([1;1;1]))
ans =
1 3
1 3
1 3
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!