proof if value is greatest of a range of Values
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
KL
on 12 Dec 2017
Edited: KL
on 12 Dec 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 Comments
KL
on 13 Dec 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.
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!