proof if value is greatest of a range of Values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
KL
le 12 Déc 2017
Modifié(e) : KL
le 12 Déc 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 commentaires
KL
le 13 Déc 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.
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!