Borrar filtros
Borrar filtros

how to read the data from vector

21 visualizaciones (últimos 30 días)
Chaoyang Jiang
Chaoyang Jiang el 27 de Mzo. de 2018
Comentada: Chaoyang Jiang el 28 de Mzo. de 2018
a=randi(10000,[10000,1]);
b=randi(10000,[10000,1]);
c=randi(100,[10000,10000]);
My question is how to find the row index of c where the c equals 5 (a is the x coordinate and b is the y coordinate).
I can do it using loop:
index=zeros(length(a),1);
for i=1:length(a)
index(i)=(c(a(i),b(i))==5);
end
index1=find(index);
May I know how to do it more efficiently whithout the use of for loop?

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Mzo. de 2018
You cannot. Your a values are up to 10000 but your c array is only 1000 on a side.
If you were to fix the ranges of a and b then
d = c(sub2ind(size(c), a, b));
  2 comentarios
Walter Roberson
Walter Roberson el 28 de Mzo. de 2018

You changed your question.

index1 = find( c(sub2ind(size(c), a, b)) == 5);
Chaoyang Jiang
Chaoyang Jiang el 28 de Mzo. de 2018
Thank you very much for your answer!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre EEG/MEG/ECoG en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by