Borrar filtros
Borrar filtros

proof if value is greatest of a range of Values

1 visualización (últimos 30 días)
Jonas Maurer
Jonas Maurer el 12 de Dic. de 2017
Comentada: KL el 13 de Dic. de 2017
Dear all,
i have got following problem. I am very thankful for any answer! See m+/-50: I want to refer to a range of rows and see if for example cell(230,1) has got the greatest value of all 50 cells above and below it (180:280,1). I tried with: (m-50:m+50,1) but it doesn´t work. Can u help me?
if true
for m=1:e-a
if X(m,3)==1 && X(m,1)>=X(m+/-50,1)
X(m,5)=1;
else
disp('zero')
end
end

Respuestas (1)

KL
KL el 12 de Dic. de 2017
Editada: KL el 12 de Dic. de 2017
Yes, you could do that but I'm unsure if you'd really need a for-loop. If you could explain your real intentions, the actual solution maybe simpler. I'm gonna assume you know you'd need it only this way.
range = 50;
sz = size(X);
for k=1:sz(1)
if X(k)>=X(max(1,k-range):min(k+range,sz(1)))
X(k)
else
disp('nada')
end
end
Here I've considered to be a vector(you could simply add the second index when you write it for a matrix) and I check if the k-th element is greater or equal to the biggest of the elements within the given range. I have used max and min, so we cover the range where we have less elements on either side.
  3 comentarios
Jonas Maurer
Jonas Maurer el 13 de Dic. de 2017
It´s me again. I found it works with the code below. But is there any option to use a word instead of the ouput 1. I tried with disp('bla'), but this on states to many output arguments. Thanks for your help a lot!! I am very glad to make progress!
for m=51:e-a-51
if X(m,2)<=50 && X(m,1)==max(X(m-50:m+50,1))
X(m,3)=1;
else
X(m,3)=0;
end
end
KL
KL el 13 de Dic. de 2017
Very good, yeah, that's the idea. If you want to store words, you cannot use a numeric matrix, obviously. Alternative is to use a cell array or a table. They both help you store different data types together in a matrix like format but latter would be my suggestion.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing 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