フィルターのクリア

Referencing value of an array based on the values of another

5 ビュー (過去 30 日間)
SB
SB 2019 年 9 月 12 日
編集済み: Walter Roberson 2019 年 9 月 12 日
I have an array d = [0,1000,2000]. Based on this array, I compute the value of another array, let's say J = [0,5000,8000], where J = 3*d+2000.
Now, during iteration using a for loop, if d=0, I want to extract value of J(1); if d = 1000, then I want to extract values of J(1) and J(2); if d = 2000, I want to extract values of J(1),J(2) and J(3). What would be a generic way to cross reference values of two arrays?

採用された回答

Walter Roberson
Walter Roberson 2019 年 9 月 12 日
編集済み: Walter Roberson 2019 年 9 月 12 日
[~, idx] = ismember(current_d, list_of_d);
J(1:idx)
If your permitted d are sorted, then
J(1:cumsum(current_d <= list_of_d))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by