フィルターのクリア

find matrix values ​​and print to another matrix

1 回表示 (過去 30 日間)
Esra Demirbilek
Esra Demirbilek 2022 年 3 月 29 日
回答済み: Voss 2022 年 3 月 29 日
Hello everyone
I want to print machine times in the column next to the values ​​in the result matrix. How can I do it? Each value in the result matrix represents jobs.
The duration of the jobs is given in the machine times matrix.
Result matris;
10
5
9
1
Machine Times
Work times
1 3
2 5
3 12
4 8
5 9
6 7
7 10
9 5
10 2
For example; ı want to do this
result;
10 2
5 9
9 5
1 3
thanks in advance

採用された回答

Voss
Voss 2022 年 3 月 29 日
You can use ismember() with its second output argument:
% Machine Times
% Work times
lookup = [ ...
1 3
2 5
3 12
4 8
5 9
6 7
7 10
9 5
10 2];
M = [ ...
10
5
9
1];
[~,idx] = ismember(M,lookup(:,1)); % idx: row in the first column of lookup where each element of M occurs
result = [M lookup(idx,2)] % result is M followed by corresponding elements from column 2 of lookup
result = 4×2
10 2 5 9 9 5 1 3

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by