How to get score of each combination of pairs in each tool

1 view (last 30 days)
Hi,
I have score of a different combination of recipe pairs in each tool, now I give available recipes and want to get the score of each possible combination of recipes in each tool,
Score_data:
Tool Pair Score
Tool1 AB 40
Tool1 AS 37
Tool1 AT 11
Tool1 SA 23
Tool1 ST 37
Tool1 TA 39
Tool1 TB 17
Tool1 BA 39
Tool2 BA 23
Tool2 BS 40
Tool2 BT 39
Tool2 SA 36
Tool2 ST 33
Tool2 AS 10
Tool3 AB 11
Tool3 AS 21
Tool3 AT 26
Tool3 BA 38
Tool3 BS 12
Tool3 BT 39
Tool3 ST 21
Tool3 TA 0
Tool4 AB 23
Tool4 BT 40
Tool4 SA 0
Tool4 TB 11
Tool4 AT 40
Tool4 BA 0
Tool4 BS 10
AB means: A-->B pair,AS means A-->S pair etc.
Now I want to get possible score of given recipes in each tool,
New_recipes:
A
B
S
T
D
N
My desired output: If any pair's score not available then it is NA in the desired output.
AB AS AT AD AN BA BS BT BD BN SA SB ST SD SN TA TB TD TN
Tool1 40 37 11 NA NA 39 NA NA NA NA 23 NA 37 NA NA 39 17 NA NA
Tool2 NA 10 NA NA NA 23 40 39 NA NA NA NA 33 NA NA NA 11 NA NA
Tool3 11 21 26 NA NA 38 12 39 NA NA 36 NA 21 NA NA 0 NA NA NA
Tool4 23 NA 40 NA NA 0 10 40 NA NA 0 NA NA NA NA NA NA NA NA
Many thnaks in advance,

Accepted Answer

Guillaume
Guillaume on 24 Feb 2018
Edited: Guillaume on 24 Feb 2018
Very easily done if your data is in a table, using unstack:
toolscore = readtable('scoredata.txt'); %after saving your example in a text file
unstack(toolscore, 'Score', 'Pair')
  7 Comments
Guillaume
Guillaume on 26 Feb 2018
Well, yes, you commented out the first line, which reads the file into a table. As I wrote in the first line of my answer:
"Very easily done if your data is in a table using unstack"
Get rid of the outdated xlsread and use readtable instead, as per my answer.
Mekala balaji
Mekala balaji on 27 Feb 2018
Sir,
but my scoreInput file will be either in xlsx or csv format,
do I need to preprocess the data such as read data first (from xlsx or csv), then form a table

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!