how to find specific columns using vectors
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a matrix U (n*m) and vectors v(1)-v(m) [not the same size]. I want for every vector to find in the respective row (for vector v1 is row 1) the columns that have the vector number(for v1 [1; 8; 12; 52; 68; 93; 150; 189;] it selects columns 1,8,12,52,68,93,150,189) and then finds the 5 values that are closest to zero and rerurns vector v'(1)-v'(m) that have the number of the respective column(for example: v'(1)=[1;12;52;68;189;])
0 comentarios
Respuestas (1)
MiguelMauricio
el 6 de Jun. de 2014
I am not sure I understood it completely
newMatrix=zeros(5,m);
for i =1:m
rowU=U(:,i);
%If you meant the columns with the indexes appearing in the vector v(i)
indexes=v(i);
%If you meant the columns with the same values as in the vector v(i)
indexes=v(i)==rowU; %But v(i) and rowU must have the same length
elementsRow=rowU(indexes);
sortedElements=sort(abs(elementsRow)); %Close to zero in absolute value
newMatrix(:,i)=sortedElements(1:5);
end
0 comentarios
Ver también
Categorías
Más información sobre Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!