MATLAB Answers

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

2 views (last 30 days)
Mekala balaji
Mekala balaji on 23 Feb 2018
Commented: Mekala balaji on 27 Feb 2018
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,

  0 Comments

Sign in to comment.

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

Show 4 older comments
Mekala balaji
Mekala balaji on 26 Feb 2018
I followed your code and tried, but some error,
my code:
close all
clear all
clc
[~,~,toolscore]=xlsread('scoreInput.xlsx');
% toolscore = readtable('scoredata.txt');
pairscore = unstack(toolscore, 'Score', 'Pair');
[half1, half2] = ndgrid('ABSTDN');
allpairs = cellstr([half2(~eye(size(half2))), half1(~eye(size(half1)))]); %the eye is to remove pairs with identical values such as AA, BB, ...
fullpairscore = [pairscore(:, 1), array2table(nan(height(pairscore), numel(allpairs)), 'VariableNames', allpairs)];
fullpairscore(:, pairscore.Properties.VariableNames) = pairscore;
Error:
Undefined function 'unstack' for input arguments of type 'cell'.
Error in crossToolScore (line 6)
pairscore = unstack(toolscore, 'Score', 'Pair');
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)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!

Translated by