How to do interpolation

3 次查看(过去 30 天)
Hi, I have below cell array data:
Category Player1 Player2 Time
Category1 A B 10
Category1 T P 12
Category1 A T 23
Category1 T B 46
Category2 U L 51
Category2 O C 51
Category2 G J 71
Category2 P X 58
Category2 D F 69
I Want to calculate the score by each category separately, Maximum score is 100 & minimum score is 1
For Category1, the player pair (pair is: Player1 -->Player2) has lesss time will get highest score
1. Player pair having Minimum time score will be 100(Player A-->B)
2. Player pair having Maximum time score will be 1(Player T-->B)
and then interpolated for other player pairs.
For Category2:
1. U-->L & O-->C will get score 100
2. G-->J will get score 1
3. Other player pairs will be interpolated
Many thanks in advance for your kind help,

采纳的回答

Bob Thompson
Bob Thompson 2018-3-8
I would suggest making a new array to set your highest and lowest values. Then you can use the interp1() function. https://www.mathworks.com/help/matlab/ref/interp1.html
interparray(1,:) = [100, max(data(:,4))];
interparray(2,:) = [1,min(data(:,4))];
for k = 1:size(data,1);
data(k,5) = interp1(interparray(:,2),interparray(:,1),data(k,4));
end
Obviously the indexing for this bit is set up for a regular double array, while it appears you have a table, but just adjust the indexing and the concept should still work fine.
  1 个评论
Mekala balaji
Mekala balaji 2018-3-9
I tries as below:
clc;
[~,~,dataTemp] = xlsread('Interpolation_Input.xlsx');
data=dataTemp(2:end,:);
interparray(1,:) = [100, max(cell2mat(data(:,4)))];
interparray(2,:) = [1,min(cell2mat(data(:,4)))];
for k = 1:size(data,1)
data(k,5) = interp1(interparray(:,2),interparray(:,1),data(k,4));
end
It give below error:
Error using interp1 (line 171) Inputs must be floats, namely single or double.
Error in InterpolationRCP (line 7) data(k,5) = interp1(interparray(:,2),interparray(:,1),data(k,4));

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by