How to find the exact values in a column and make a computation according to the next column of it?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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..
0 commentaires
Réponse acceptée
Guillaume
le 22 Fév 2016
Modifié(e) : Guillaume
le 22 Fév 2016
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Elementary Math dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!