Compare column vector to matrix

5 visualizaciones (últimos 30 días)
Simon
Simon el 5 de Ag. de 2016
Comentada: Simon el 5 de Ag. de 2016
Hello,
I'm trying to find the first element and its index into a 73X615 matrix, where each value should be less or equal to a value in 73X1 column vector. So let's say that the matrix is
B = -5 + (5+1)*rand(73,615);
and the vector is
A = -5 + (5+1)*rand(73,1)
My intention is to extract a columns vectors [C, iC], where each value of C is the first value in B that is less or equal than the value in A at the corresponding row, and iC is the index of that value.
My apologies if the question seems a bit contrived, but I'm new to Matlab and I didn't know how to formulate it more clearly.
I hope you can help me with this issue, before hand, many thanks.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 5 de Ag. de 2016
Editada: Azzi Abdelmalek el 5 de Ag. de 2016
B = -5 + (5+1)*rand(73,615)
A = -5 + (5+1)*rand(73,1)
id=bsxfun(@le,B,A)
for k=1:size(id,1)
ii=find(id(k,:),1)
out(k,1:2)=[B(k,ii) ii]
end
Incase there are empty indices
B = -5 + (5+1)*rand(73,615)
A = -5 + (5+1)*rand(73,1)
id=bsxfun(@le,B,A)
kk=0
for k=1:size(id,1)
ii=find(id(k,:),1)
if ~isempty(ii)
kk=kk+1
out(kk,1:2)=[B(k,ii) ii]
end
end
out
  7 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 5 de Ag. de 2016
Simon, this is not how it works in this forum, when an answer satisfies your need, you have to mark the answer as accepted. You can also ask for some explanations related to your question, if it's not you have to post another question.
Simon
Simon el 5 de Ag. de 2016
I'm sorry, it's my first time using the forum. I'll open other question.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification 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!

Translated by