proof if value is greatest of a range of Values
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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 件のコメント
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 Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!