フィルターのクリア

proof if value is greatest of a range of Values

1 回表示 (過去 30 日間)
Jonas Maurer
Jonas Maurer 2017 年 12 月 12 日
コメント済み: KL 2017 年 12 月 13 日
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

回答 (1 件)

KL
KL 2017 年 12 月 12 日
編集済み: KL 2017 年 12 月 12 日
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 件のコメント
Jonas Maurer
Jonas Maurer 2017 年 12 月 13 日
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 2017 年 12 月 13 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by