Creating a general Product-Operations Matrix with the help of loops
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all,
I am currently working on a way to create a Product-Operations Matrix which should look something like this: Columns: listing all Products Rows: all operations needed for all products
So for example M(1,3)=1 and M(4,3)=1 means Product 3 is produced using Operations 1 and 4.
The idea is to analyse this Matrix in a later stage in order to find Products that have similar operations.
Right now, I have used MS Access to export the Operations for each Product, the Table looks like this:
ProductNo. OperationID OperationTime
1 A 0.1
1 C 0.3
1 D 0.4
1 E 0.5
2 A 0.1
2 B 0.6
3 E 0.5
3 A 0.1
I would like to create according Matrix that looks like this:
0.1 0.1 0.1
0 0.6 0
0.3 0 0
0.4 0 0
0.5 0 0.5
I guess I have to use many for-loops, but I just cannot wrap my head around it... Thank you so much for your help!
0 Kommentare
Antworten (1)
Kevin Gleason
am 2 Nov. 2016
I would suggest you create a helper function as follows:
% Get the index of a letter A=1, B=2, ..., E=5
letterIdx = @(letter) letter-'A' +1;
This will correlate whatever letter is in Column 2 (OperationID) to an index in the final matrix. Next we can create a matrix of zeros in the size of your data:
prodOps = zeros(5,3);
Finally you can populate your "prodOps" matrix by using a single loop over every row of your data and fill in "prodOps" as follows:
prodOps(col1, letterIdx(col2)) = col3;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements 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!