Determine value in the 3rd column of a matrix based on the first and second column values

1 回表示 (過去 30 日間)
I have a matrix, say like this:
M = [3 2 10; 4 3 4; 3 1 3; 2 1 12; 2 2 10; 4 1 18; 4 2 12];
Where the order is like this: [job, machine, production_time]
So based on the job and the machine the job should be on, I want to deduce the production time on it.
I can not seem to find anything that can do this for me. Any help is appreciated!

採用された回答

Dyuman Joshi
Dyuman Joshi 2024 年 1 月 12 日
編集済み: Dyuman Joshi 2024 年 1 月 12 日
Use ismember -
M = [3 2 10; 4 3 4; 3 1 3; 2 1 12; 2 2 10; 4 1 18; 4 2 12];
job = 3;
machine = 2;
idx = ismember(M(:,1:2), [job machine], 'rows')
idx = 7×1 logical array
1 0 0 0 0 0 0
out = M(idx, 3)
out = 10
If you are working with non-integral values, ismembertol should be preferred instead.
If job and machine contain multiple values, compare them individually and use those indices to get the corresponding values as per requirement.
  3 件のコメント
Lars Meijer
Lars Meijer 2024 年 1 月 15 日
This works exactly as I want it to! Thanks a lot.
Dyuman Joshi
Dyuman Joshi 2024 年 1 月 15 日
Great! Glad to have helped :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTiming and presenting 2D and 3D stimuli についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by