How to find the exact values in a column and make a computation according to the next column of it?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
bilgesu ak
am 22 Feb. 2016
Kommentiert: bilgesu ak
am 22 Feb. 2016
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 Kommentare
Akzeptierte Antwort
Guillaume
am 22 Feb. 2016
Bearbeitet: Guillaume
am 22 Feb. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Elementary Math finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!