Hi everyone,
I have a vector A containing a range of values
A = [ 0 25 50 75 100 125 150 ]
and I want to assign values to a second vector B with the same size than A, depending on the following criteria:
% B(i) = 1 for A(i) <= 50
% B(i) = 2 for 50 < A(i) <= 100
% B(i) = 3 for 100 < A(i)
these are stored in the variables X and Y:
X = [ 1 2 3 ] % values to be assigned to B
Y = [ 0 50 100 inf ] % range limits for X
the result should be:
A = [ 0 25 50 75 100 125 150 ]
B = [ 1 1 1 2 2 3 3 ]
Is there any short way to do this?

 採用された回答

John D'Errico
John D'Errico 2020 年 6 月 10 日

1 投票

Read about discretize. It does exactly what you want.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Startup and Shutdown についてさらに検索

質問済み:

2020 年 6 月 10 日

回答済み:

2020 年 6 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by