フィルターのクリア

changing values in matrix to numbers from particular range

12 ビュー (過去 30 日間)
Pawel Szczepanowski
Pawel Szczepanowski 2021 年 12 月 21 日
コメント済み: Pawel Szczepanowski 2021 年 12 月 21 日
hi, I have matrix X =[1,5,10,14,25;22,30,28,4,2]. I would like to change values of this matrix i this way:
if value is from range: 1:5 change it to 1, 6:10 change it to 2, 11:15 change it to 3, 16:20 change it to 4, 21:25 change it to 5, 26:30 change it to 6.
In result i would like to get matrix [1,1,2,3,5; 5,6,6,1,1].
I try something like this: X(X(1:5)==1, etc... but this does not work well.
Do you have aby ideas?
Thanku you in advance.

採用された回答

Voss
Voss 2021 年 12 月 21 日
X = [1,5,10,14,25;22,30,28,4,2];
display(X);
X = 2×5
1 5 10 14 25 22 30 28 4 2
X(X >= 1 & X <= 5) = 1;
X(X >= 6 & X <= 10) = 2;
% and so on for the rest of the ranges
display(X);
X = 2×5
1 1 2 14 25 22 30 28 1 1

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by