Finding specific values from a matrix

2 ビュー (過去 30 日間)
stelios loizidis
stelios loizidis 2022 年 10 月 4 日
コメント済み: stelios loizidis 2022 年 10 月 4 日
Hello,
I have the matrix Values (1X3000), upper limit (=100) and lower limit(=30). What I want is for the Specific_Values matrix to contain the values that satisfy the following relationship,
lower_limit<= Values<=upper_limit
Below is the code I wrote but all the values of Values matrix are entered in the Specific_Values matrix.
Values % 1X3000
lower_limit=30;
upper_limit=100;
for i=1:length(Values)
if (Values(i)>=lower_limit && Values<=upper_limit)
Specific_Values(i)=Values(i);
end
end
How to solve this problem? Your help is invaluable.

採用された回答

Davide Masiello
Davide Masiello 2022 年 10 月 4 日
See the example below (I used a smaller array for better readibility)
Values = randi(200,1,20)
Values = 1×20
102 75 138 153 162 13 178 156 128 9 71 131 25 123 194 170 22 7 200 159
lower_limit=30;
upper_limit=100;
Specific_Values = Values(Values >= lower_limit & Values <= upper_limit)
Specific_Values = 1×2
75 71
  1 件のコメント
stelios loizidis
stelios loizidis 2022 年 10 月 4 日
It works. Thanks for the valuable help!!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by