How to find the exact values in a column and make a computation according to the next column of it?

4 ビュー (過去 30 日間)
Hi; I have matrix that first column shows task numbers, second column shows the station numbers that tasks assigned and third column shows the machine types assigned to regarding stations..
For example:
A=
1 1 1
5 1 2
4 2 2
2 2 2
3 3 2
7 3 1
6 4 2
9 4 1
this matrix says that task 1 and task 5 assigned to workstation1 and machice type 1 and machine type 2 is neccesarry.
task 4 and task 2 assigned to workstation2 and only machine 2 is neccesarry and only 1 machine2 is neccasary (two tasks are assigned to one machine). Now I want to compute the machine numbers for the stations that :
mac=
2
1
2
2
Thanks in advance;
Regards..

採用された回答

Guillaume
Guillaume 2016 年 2 月 22 日
編集済み: Guillaume 2016 年 2 月 22 日
It's not very clear what you're asking. If all you want is to know how many different machines are required for each station, it's simply:
A = [1 1 1
5 1 2
4 2 2
2 2 2
3 3 2
7 3 1
6 4 2
9 4 1];
mac = accumarray(A(:, 2), A(:, 3), [], @(x) numel(unique(x)))
accumarray groups the machines by station and the anonymous function @(x) numel(unique(x)) counts the number of unique machine for each station.
Note that the code will only work correctly if the stations are consecutive integers starting at 1. If not:
[station, ~, subs] = unique(A(:, 2));
mac = accumarray(subs, A(:, 3), [], @(x) numel(unique(x)))
will work regardless of the station values.
  1 件のコメント
bilgesu ak
bilgesu ak 2016 年 2 月 22 日
Thank you Guillaume very much. My station numbers starts from 1 and it works right..
With my regards...

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by